/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/internal/Magento/Framework/View/Layout/BuilderFactory.php
83 строки
2 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 17:47
22 окт 2025, 17:47
1b769b7
Код
Авторство
О чём код?
<?php /** * Copyright 2014 Adobe * All Rights Reserved. */ namespace Magento\Framework\View\Layout; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\View; /** * Class BuilderFactory */ class BuilderFactory { /**#@+ * Allowed builder types */ const TYPE_LAYOUT = 'layout'; const TYPE_PAGE = 'page'; /**#@-*/ /**#@-*/ protected $typeMap = [ self::TYPE_LAYOUT => \Magento\Framework\View\Layout\Builder::class, self::TYPE_PAGE => \Magento\Framework\View\Page\Builder::class, ]; /** * @var ObjectManagerInterface */ protected $objectManager; /** * Constructor * * @param ObjectManagerInterface $objectManager * @param array $typeMap */ public function __construct( ObjectManagerInterface $objectManager, array $typeMap = [] ) { $this->objectManager = $objectManager; $this->mergeTypes($typeMap); } /** * Add or override builder types * * @param array $typeMap * @return void */ protected function mergeTypes(array $typeMap) { foreach ($typeMap as $typeInfo) { if (isset($typeInfo['type']) && isset($typeInfo['class'])) { $this->typeMap[$typeInfo['type']] = $typeInfo['class']; } } } /** * Create builder instance * * @param string $type * @param array $arguments * @throws \InvalidArgumentException * @return BuilderInterface */ public function create($type, array $arguments) { if (empty($this->typeMap[$type])) { throw new \InvalidArgumentException('"' . $type . ': isn\'t allowed'); } $builderInstance = $this->objectManager->create($this->typeMap[$type], $arguments); if (!$builderInstance instanceof BuilderInterface) { throw new \InvalidArgumentException(get_class($builderInstance) . ' isn\'t instance of BuilderInterface'); } return $builderInstance; } }