Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Resolver.php
Go to the documentation of this file.
1 <?php
8 
9 class Resolver
10 {
11  const CATALOG_LAYER_CATEGORY = 'category';
12  const CATALOG_LAYER_SEARCH = 'search';
13 
19  protected $layersPool;
20 
26  protected $objectManager;
27 
31  protected $layer = null;
32 
37  public function __construct(
39  array $layersPool
40  ) {
41  $this->objectManager = $objectManager;
42  $this->layersPool = $layersPool;
43  }
44 
51  public function create($layerType)
52  {
53  if (isset($this->layer)) {
54  throw new \RuntimeException('Catalog Layer has been already created');
55  }
56  if (!isset($this->layersPool[$layerType])) {
57  throw new \InvalidArgumentException($layerType . ' does not belong to any registered layer');
58  }
59  $this->layer = $this->objectManager->create($this->layersPool[$layerType]);
60  }
61 
67  public function get()
68  {
69  if (!isset($this->layer)) {
70  $this->layer = $this->objectManager->create($this->layersPool[self::CATALOG_LAYER_CATEGORY]);
71  }
72  return $this->layer;
73  }
74 }
__construct(\Magento\Framework\ObjectManagerInterface $objectManager, array $layersPool)
Definition: Resolver.php:37