vendor/doctrine/phpcr-bundle/src/Command/NodeTypeRegisterCommand.php line 13

Open in your IDE?
  1. <?php
  2. namespace Doctrine\Bundle\PHPCRBundle\Command;
  3. use PHPCR\Util\Console\Command\NodeTypeRegisterCommand as BaseRegisterNodeTypesCommand;
  4. use Symfony\Component\Console\Input\InputInterface;
  5. use Symfony\Component\Console\Input\InputOption;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. /**
  8.  * Wrapper to use this command in the symfony console with multiple sessions.
  9.  */
  10. class NodeTypeRegisterCommand extends BaseRegisterNodeTypesCommand
  11. {
  12.     private const BUNDLE_NT_PATH 'Resources/config/phpcr-node-types';
  13.     /**
  14.      * {@inheritdoc}
  15.      */
  16.     protected function configure()
  17.     {
  18.         parent::configure();
  19.         $newHelp = <<<'EOT'
  20. If no cnd-files are specified, the command will automatically try and find node files in the
  21. <comment>%s</comment> directory of activated bundles.
  22. EOT;
  23.         $help $this->getHelp().sprintf($newHelpself::BUNDLE_NT_PATH);
  24.         $this
  25.             ->setName('doctrine:phpcr:node-type:register')
  26.             ->addOption('session'nullInputOption::VALUE_REQUIRED'The session to use for this command')
  27.             ->setHelp($help)
  28.         ;
  29.     }
  30.     /**
  31.      * {@inheritdoc}
  32.      */
  33.     protected function execute(InputInterface $inputOutputInterface $output)
  34.     {
  35.         DoctrineCommandHelper::setApplicationPHPCRSession(
  36.             $this->getApplication(),
  37.             $input->getOption('session'),
  38.             true
  39.         );
  40.         $definitions $input->getArgument('cnd-file');
  41.         $application $this->getApplication();
  42.         // if no cnd-files, automatically load from bundles
  43.         if (=== \count($definitions)) {
  44.             $bundles $application->getKernel()->getBundles();
  45.             $candidatePaths = [];
  46.             foreach ($bundles as $bundle) {
  47.                 $candidatePath sprintf('%s/%s'$bundle->getPath(), self::BUNDLE_NT_PATH);
  48.                 if (!file_exists($candidatePath)) {
  49.                     continue;
  50.                 }
  51.                 $candidatePaths[] = $candidatePath;
  52.             }
  53.             if (=== \count($candidatePaths)) {
  54.                 $output->writeln(sprintf(
  55.                     'No definition files specified and could not find any definitions in any <comment><bundle>/%s</comment> folders. Aborting.',
  56.                     self::BUNDLE_NT_PATH
  57.                 ));
  58.                 return 1;
  59.             }
  60.             $input->setArgument('cnd-file'$candidatePaths);
  61.         }
  62.         return parent::execute($input$output);
  63.     }
  64. }