/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/internal/Magento/Framework/Controller/ResultFactory.php
106 строк
3 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\Controller; use Magento\Framework\ObjectManagerInterface; /** * Result Factory * * @api * @since 100.0.2 */ class ResultFactory { /**#@+ * Allowed result types */ const TYPE_JSON = 'json'; const TYPE_RAW = 'raw'; const TYPE_REDIRECT = 'redirect'; const TYPE_FORWARD = 'forward'; const TYPE_LAYOUT = 'layout'; const TYPE_PAGE = 'page'; /**#@-*/ /**#@-*/ protected $typeMap = [ self::TYPE_JSON => Result\Json::class, self::TYPE_RAW => Result\Raw::class, self::TYPE_REDIRECT => Result\Redirect::class, self::TYPE_FORWARD => Result\Forward::class, self::TYPE_LAYOUT => \Magento\Framework\View\Result\Layout::class, self::TYPE_PAGE => \Magento\Framework\View\Result\Page::class, ]; /** * @var ObjectManagerInterface */ private $objectManager; /** * Constructor * * @param ObjectManagerInterface $objectManager * @param array $typeMap */ public function __construct( ObjectManagerInterface $objectManager, array $typeMap = [] ) { $this->objectManager = $objectManager; $this->mergeTypes($typeMap); } /** * Add or override result 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 new page regarding its type * * @param string $type * @param array $arguments * @throws \InvalidArgumentException * @return ResultInterface */ public function create($type, array $arguments = []) { if (empty($this->typeMap[$type])) { throw new \InvalidArgumentException('"' . $type . ': isn\'t allowed'); } $resultInstance = $this->objectManager->create($this->typeMap[$type], $arguments); if (!$resultInstance instanceof ResultInterface) { throw new \InvalidArgumentException(get_class($resultInstance) . ' isn\'t instance of ResultInterface'); } /** * TODO: Temporary solution, must be removed after full refactoring to the new result rendering system * * Used for knowledge how result page was created, page was created through result factory or it's default page * in App\View created in constructor */ if ($resultInstance instanceof \Magento\Framework\View\Result\Layout) { // Initialization has to be in constructor of ResultPage $resultInstance->addDefaultHandle(); } return $resultInstance; } }