Spamworldpro Mini Shell
Spamworldpro


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/Setup/Declaration/Schema/Dto/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/framework/Setup/Declaration/Schema/Dto/ElementFactory.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Framework\Setup\Declaration\Schema\Dto;

use Magento\Framework\Stdlib\BooleanUtils;
use Magento\Framework\Setup\Declaration\Schema\Dto\Factories\FactoryInterface;

/**
 * DTO Element factory.
 *
 * Instantiates any type of structural elements.
 *
 * @see ElementInterface
 */
class ElementFactory
{
    /**
     * Predefined types of elements, that can be instantiated using this factory.
     *
     * Where @key - is xsi:type of the object
     * Where @value - is instance class name
     */
    private $typeFactories = [];

    /**
     * @var BooleanUtils
     */
    private $booleanUtils;

    /**
     * Constructor.
     *
     * @param FactoryInterface[] $typeFactories
     * @param BooleanUtils       $booleanUtils
     */
    public function __construct(
        array $typeFactories,
        BooleanUtils $booleanUtils
    ) {
        $this->typeFactories = $typeFactories;
        $this->booleanUtils = $booleanUtils;
    }

    /**
     * Cast generic attributes.
     *
     * Common attributes for multiple types:
     *  - nullable
     *  - unsigned
     *  - identity
     * Casted to boolean value in factory.
     *
     * @param  array $elementStructuralData
     * @return array
     */
    private function castGenericAttributes(array $elementStructuralData)
    {
        $booleanAttributes = ['nullable', 'unsigned', 'identity'];

        foreach ($booleanAttributes as $booleanAttribute) {
            if (isset($elementStructuralData[$booleanAttribute])) {
                $elementStructuralData[$booleanAttribute] = $this->booleanUtils
                    ->toBoolean($elementStructuralData[$booleanAttribute]);
            }
        }

        return $elementStructuralData;
    }

    /**
     * Instantiate different types of elements, depends on their xsi:type.
     *
     * @param  string $type
     * @param  array  $elementStructuralData
     * @return ElementInterface | object
     */
    public function create($type, array $elementStructuralData)
    {
        if (!isset($this->typeFactories[$type])) {
            throw new \InvalidArgumentException(sprintf("Types %s is not declared", $type));
        }

        $elementStructuralData = $this->castGenericAttributes($elementStructuralData);
        $elementStructuralData['type'] = $type;
        return $this->typeFactories[$type]->create($elementStructuralData);
    }
}

Spamworldpro Mini