Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DatabaseMapPool.php
Go to the documentation of this file.
1 <?php
7 
9 
14 {
18  private $dataArray = [];
19 
23  private $objectManager;
24 
30  public function __construct(
31  ObjectManagerInterface $objectManager
32  ) {
33  $this->objectManager = $objectManager;
34  }
35 
43  public function getDataMap($instanceName, $categoryId)
44  {
45  $key = $instanceName . '-' . $categoryId;
46  if (!isset($this->dataArray[$key])) {
47  $instance = $this->objectManager->create(
48  $instanceName,
49  [
50  'category' => $categoryId
51  ]
52  );
53  if (!$instance instanceof DatabaseMapInterface) {
54  throw new \InvalidArgumentException(
55  $instanceName . ' does not implement interface ' . DatabaseMapInterface::class
56  );
57  }
58  $this->dataArray[$key] = $instance;
59  }
60  return $this->dataArray[$key];
61  }
62 
70  public function resetMap($instanceName, $categoryId)
71  {
72  $key = $instanceName . '-' . $categoryId;
73  if (isset($this->dataArray[$key])) {
74  $this->dataArray[$key]->destroyTableAdapter($categoryId);
75  unset($this->dataArray[$key]);
76  }
77  }
78 }
$objectManager
Definition: bootstrap.php:17
__construct(ObjectManagerInterface $objectManager)