vendor/sonata-project/block-bundle/src/Command/DebugBlocksCommand.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <[email protected]>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\BlockBundle\Command;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Input\InputOption;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Symfony\Component\OptionsResolver\OptionsResolver;
  16. class DebugBlocksCommand extends BaseCommand
  17. {
  18.     /**
  19.      * {@inheritdoc}
  20.      */
  21.     public function configure()
  22.     {
  23.         // NEXT_MAJOR: Switch name and alias
  24.         $this->setAliases(['debug:sonata:block']);
  25.         $this->setName('sonata:block:debug');
  26.         $this->setDescription('Debug all blocks available, show default settings of each block');
  27.         $this->addOption('context''c'InputOption::VALUE_REQUIRED'display service for the specified context');
  28.     }
  29.     /**
  30.      * {@inheritdoc}
  31.      */
  32.     public function execute(InputInterface $inputOutputInterface $output)
  33.     {
  34.         if ($input->getOption('context')) {
  35.             $services $this->getBlockServiceManager()->getServicesByContext($input->getOption('context'));
  36.         } else {
  37.             $services $this->getBlockServiceManager()->getServices();
  38.         }
  39.         foreach ($services as $code => $service) {
  40.             $resolver = new OptionsResolver();
  41.             // NEXT_MAJOR: Remove this check
  42.             if (method_exists($service'configureSettings')) {
  43.                 $service->configureSettings($resolver);
  44.             } else {
  45.                 $service->setDefaultSettings($resolver);
  46.             }
  47.             $settings $resolver->resolve();
  48.             $output->writeln('');
  49.             $output->writeln(sprintf('<info>>> %s</info> (<comment>%s</comment>)'$service->getName(), $code));
  50.             foreach ($settings as $key => $val) {
  51.                 $output->writeln(sprintf('    %-30s%s'$keyjson_encode($val)));
  52.             }
  53.         }
  54.         $output->writeln('done!');
  55.     }
  56. }