Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MetadataPool.php
Go to the documentation of this file.
1 <?php
8 
11 
19 {
24  protected $objectManager;
25 
30  protected $metadata;
31 
36  protected $registry;
37 
42  protected $sequenceFactory;
43 
50  public function __construct(
53  array $metadata
54  ) {
55  $this->objectManager = $objectManager;
56  $this->sequenceFactory = $sequenceFactory;
57  $this->metadata = $metadata;
58  }
59 
64  private function createMetadata($entityType)
65  {
66  //@todo: use ID as default if , check is type has EAV attributes
67  $connectionName = isset($this->metadata[$entityType]['connectionName'])
68  ? $this->metadata[$entityType]['connectionName']
69  : 'default';
70  $eavEntityType = isset($this->metadata[$entityType]['eavEntityType'])
71  ? $this->metadata[$entityType]['eavEntityType']
72  : null;
73  $entityContext = isset($this->metadata[$entityType]['entityContext'])
74  ? $this->metadata[$entityType]['entityContext']
75  : [];
76  return $this->objectManager->create(
77  EntityMetadataInterface::class,
78  [
79  'entityTableName' => $this->metadata[$entityType]['entityTableName'],
80  'eavEntityType' => $eavEntityType,
81  'connectionName' => $connectionName,
82  'identifierField' => $this->metadata[$entityType]['identifierField'],
83  'sequence' => $this->sequenceFactory->create($entityType, $this->metadata),
84  'entityContext' => $entityContext
85  ]
86  );
87  }
88 
95  public function getMetadata($entityType)
96  {
97  if (!isset($this->metadata[$entityType])) {
98  throw new \Exception(sprintf('Unknown entity type: %s requested', $entityType));
99  }
100  if (!isset($this->registry[$entityType])) {
101  $this->registry[$entityType] = $this->createMetadata($entityType);
102  }
103  return $this->registry[$entityType];
104  }
105 
112  public function getHydrator($entityType)
113  {
115  return $objectManager->get(HydratorPool::class)->getHydrator($entityType);
116  }
117 
125  public function hasConfiguration($entityType)
126  {
127  return isset($this->metadata[$entityType]);
128  }
129 }
__construct(ObjectManagerInterface $objectManager, SequenceFactory $sequenceFactory, array $metadata)