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

AddBlockCommand.php

Blame
  • AddBlockCommand.php 1.79 KiB
    <?php
    declare(strict_types=1);
    
    namespace Firegento\ContentProvisioning\Model\Console;
    
    use Firegento\ContentProvisioning\Model\Command\ApplyBlockEntry;
    use Firegento\ContentProvisioning\Model\Query\GetBlockEntryByKey;
    use Firegento\ContentProvisioning\Model\Query\GetBlockEntryList\Proxy as GetBlockEntryList;
    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputArgument;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    
    class AddBlockCommand extends Command
    {
        const ARG_BLOCK_KEY = 'key';
    
        /**
         * @var GetBlockEntryByKey
         */
        private $getBlockEntryByKey;
    
        /**
         * @var ApplyBlockEntry
         */
        private $applyBlockEntry;
    
        /**
         * @param GetBlockEntryList $getBlockEntryByKey
         * @param string|null $name
         */
        public function __construct(
            GetBlockEntryByKey $getBlockEntryByKey,
            ApplyBlockEntry $applyBlockEntry,
            string $name = null
        ) {
            parent::__construct($name);
            $this->getBlockEntryByKey = $getBlockEntryByKey;
            $this->applyBlockEntry = $applyBlockEntry;
        }
    
        /**
         * {@inheritdoc}
         */
        protected function execute(InputInterface $input, OutputInterface $output)
        {
            $key = $input->getArgument(self::ARG_BLOCK_KEY);
            $block = $this->getBlockEntryByKey->get($key);
            $this->applyBlockEntry->execute($block);
        }
    
        /**
         * {@inheritdoc}
         */
        protected function configure()
        {
            $this->setName('content-provisioning:block:apply');
            $this->setDescription('Add a block by key');
            $this->addArgument(
                self::ARG_BLOCK_KEY,
                InputArgument::REQUIRED,
                'The key of the block to apply.'
            );
            parent::configure();
        }
    }