Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BuilderFactory.php
Go to the documentation of this file.
1 <?php
7 
10 
15 {
19  const TYPE_LAYOUT = 'layout';
20  const TYPE_PAGE = 'page';
24  protected $typeMap = [
25  self::TYPE_LAYOUT => \Magento\Framework\View\Layout\Builder::class,
26  self::TYPE_PAGE => \Magento\Framework\View\Page\Builder::class,
27  ];
28 
32  protected $objectManager;
33 
40  public function __construct(
42  array $typeMap = []
43  ) {
44  $this->objectManager = $objectManager;
45  $this->mergeTypes($typeMap);
46  }
47 
54  protected function mergeTypes(array $typeMap)
55  {
56  foreach ($typeMap as $typeInfo) {
57  if (isset($typeInfo['type']) && isset($typeInfo['class'])) {
58  $this->typeMap[$typeInfo['type']] = $typeInfo['class'];
59  }
60  }
61  }
62 
71  public function create($type, array $arguments)
72  {
73  if (empty($this->typeMap[$type])) {
74  throw new \InvalidArgumentException('"' . $type . ': isn\'t allowed');
75  }
76 
77  $builderInstance = $this->objectManager->create($this->typeMap[$type], $arguments);
78  if (!$builderInstance instanceof BuilderInterface) {
79  throw new \InvalidArgumentException(get_class($builderInstance) . ' isn\'t instance of BuilderInterface');
80  }
81  return $builderInstance;
82  }
83 }
$type
Definition: item.phtml:13
__construct(ObjectManagerInterface $objectManager, array $typeMap=[])
$arguments