Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
HashMapPool.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 
44  public function getDataMap($instanceName, $categoryId)
45  {
46  $key = $instanceName . '-' . $categoryId;
47  if (!isset($this->dataArray[$key])) {
48  $instance = $this->objectManager->create(
49  $instanceName,
50  [
51  'category' => $categoryId
52  ]
53  );
54  if (!$instance instanceof HashMapInterface) {
55  throw new \InvalidArgumentException(
56  $instanceName . ' does not implement interface ' . HashMapInterface::class
57  );
58  }
59  $this->dataArray[$key] = $instance;
60  }
61  return $this->dataArray[$key];
62  }
63 
71  public function resetMap($instanceName, $categoryId)
72  {
73  $key = $instanceName . '-' . $categoryId;
74  if (isset($this->dataArray[$key])) {
75  $this->dataArray[$key]->resetData($categoryId);
76  unset($this->dataArray[$key]);
77  }
78  }
79 }
__construct(ObjectManagerInterface $objectManager)
Definition: HashMapPool.php:30
$objectManager
Definition: bootstrap.php:17