![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/framework/View/Layout/Argument/Interpreter/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Framework\View\Layout\Argument\Interpreter; use Magento\Framework\App\ObjectManager; use Magento\Framework\Data\Argument\InterpreterInterface; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Stdlib\BooleanUtils; /** * Interpreter that instantiates object by a class name */ class DataObject implements InterpreterInterface { /** * @var \Magento\Framework\ObjectManagerInterface */ private $objectManager; /** * @var \Magento\Framework\Stdlib\BooleanUtils */ private $booleanUtils; /** * @var string|null */ private $expectedClass; /** * @param \Magento\Framework\ObjectManagerInterface $objectManager * @param string|null $expectedClass * @param \Magento\Framework\Stdlib\BooleanUtils|null $booleanUtils */ public function __construct( ObjectManagerInterface $objectManager, ?string $expectedClass = null, ?BooleanUtils $booleanUtils = null ) { $this->objectManager = $objectManager; $this->expectedClass = $expectedClass; $this->booleanUtils = $booleanUtils ?? ObjectManager::getInstance()->get(BooleanUtils::class); } /** * @inheritdoc */ public function evaluate(array $data) { if (!isset($data['value'])) { throw new \InvalidArgumentException('Object class name is missing.'); } $shared = isset($data['shared']) ? $this->booleanUtils->toBoolean($data['shared']) : true; $className = $data['value']; $result = $shared ? $this->objectManager->get($className) : $this->objectManager->create($className); if ($this->expectedClass && !$result instanceof $this->expectedClass) { throw new \UnexpectedValueException( \sprintf('Instance of %s is expected, got %s instead.', $this->expectedClass, \get_class($result)) ); } return $result; } }