Skip to content
Snippets Groups Projects
Select Git revision
  • 1361f8bbc98874414087911a33e4b87617740cea
  • 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

Provider.php

Blame
  • Provider.php 1.41 KiB
    <?php
    declare(strict_types=1);
    
    namespace Firegento\ContentProvisioning\Model\Strategy;
    
    use Firegento\ContentProvisioning\Api\StrategyInterface;
    use Firegento\ContentProvisioning\Api\StrategyProviderInterface;
    use Magento\Framework\Exception\InputException;
    use Magento\Framework\Exception\NotFoundException;
    
    class Provider implements StrategyProviderInterface
    {
        /**
         * @var array|StrategyInterface[]
         */
        private $strategies;
    
        /**
         * Provider constructor.
         * @param StrategyInterface[] $strategies
         * @throws InputException
         */
        public function __construct(array $strategies)
        {
            foreach ($strategies as $strategy) {
                if (!($strategy instanceof StrategyInterface)) {
                    throw new InputException(__(
                        'Strategy must be instance of %interface',
                        ['interface' => StrategyInterface::class]
                    ));
                }
            }
            $this->strategies = $strategies;
        }
    
        /**
         * @param string $strategyCode
         * @return StrategyInterface
         *
         * @throws NotFoundException
         */
        public function get(string $strategyCode): StrategyInterface
        {
            $strategy = $this->strategies[$strategyCode] ?? null;
    
            if (!$strategy) {
                throw new NotFoundException(__('Strategy %strategy_code not found.', ['strategy_code' => $strategyCode]));
            }
    
            return $strategy;
        }
    }