Skip to content
Snippets Groups Projects
Select Git revision
  • 28450133c8f9fc847f0a566ff89f462c32807dcc
  • develop default protected
  • 1.3 protected
  • 1.1
  • 1.2 protected
  • 1.0
  • 13-export-cli-command
  • 1.7.0
  • 1.6.0
  • 1.5.0
  • 1.4.3
  • 1.4.2
  • 1.4.1
  • 1.4.0
  • 1.3.7
  • 1.3.6
  • 1.3.5
  • 1.3.4
  • 1.3.3
  • 1.3.2
  • 1.3.1
  • 1.3.0
  • 1.1.4
  • 1.2.5
  • 1.2.4
  • 1.2.3
  • 1.0.6
27 results

ParserChain.php

Blame
  • ParserChain.php 1.21 KiB
    <?php
    declare(strict_types=1);
    
    namespace Firegento\ContentProvisioning\Model\Config\Parser;
    
    use DOMElement;
    use Firegento\ContentProvisioning\Api\ConfigParserInterface;
    use Magento\Framework\Exception\LocalizedException;
    
    /**
     * @api
     */
    class ParserChain implements ConfigParserInterface
    {
        /**
         * @var ConfigParserInterface[]
         */
        private $parser;
    
        /**
         * @param array $parser
         * @throws LocalizedException
         */
        public function __construct(array $parser)
        {
            foreach ($parser as $parserInstance) {
                if (!($parserInstance instanceof ConfigParserInterface)) {
                    throw new LocalizedException(
                        __(
                            'Parser needs to be instance of %interface',
                            ['interface' => ConfigParserInterface::class]
                        )
                    );
                }
            }
    
            $this->parser = $parser;
        }
    
        /**
         * @param DOMElement $element
         * @return array
         */
        public function execute(DOMElement $element): array
        {
            $data = [];
    
            foreach ($this->parser as $parser) {
                $data[] = $parser->execute($element);
            }
    
            return array_merge(...$data);
        }
    }