vendor/pimcore/pimcore/bundles/GeneratorBundle/Command/BaseGeneratorCommand.php line 15

Open in your IDE?
  1. <?php
  2. namespace Pimcore\Bundle\GeneratorBundle\Command;
  3. use Pimcore\Bundle\GeneratorBundle\Command\Helper\QuestionHelper;
  4. use Pimcore\Bundle\GeneratorBundle\Generator\Generator;
  5. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  6. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  7. /**
  8.  * Base class for generator commands.
  9.  *
  10.  * The following class is copied from \Sensio\Bundle\GeneratorBundle\Command\GeneratorCommand
  11.  */
  12. abstract class BaseGeneratorCommand extends ContainerAwareCommand
  13. {
  14.     /**
  15.      * @var Generator
  16.      */
  17.     private $generator;
  18.     abstract protected function createGenerator();
  19.     protected function getGenerator(BundleInterface $bundle null)
  20.     {
  21.         if (null === $this->generator) {
  22.             $this->generator $this->createGenerator();
  23.             $this->generator->setSkeletonDirs($this->getSkeletonDirs($bundle));
  24.         }
  25.         return $this->generator;
  26.     }
  27.     protected function getSkeletonDirs(BundleInterface $bundle null)
  28.     {
  29.         $skeletonDirs = [];
  30.         if (isset($bundle) && is_dir($dir $bundle->getPath().'/Resources/GeneratorBundle/skeleton')) {
  31.             $skeletonDirs[] = $dir;
  32.         }
  33.         if (is_dir($dir $this->getContainer()->get('kernel')->getRootdir().'/Resources/GeneratorBundle/skeleton')) {
  34.             $skeletonDirs[] = $dir;
  35.         }
  36.         $skeletonDirs[] = __DIR__.'/../Resources/skeleton';
  37.         $skeletonDirs[] = __DIR__.'/../Resources';
  38.         return $skeletonDirs;
  39.     }
  40.     protected function getQuestionHelper()
  41.     {
  42.         $question $this->getHelperSet()->get('question');
  43.         if (!$question || get_class($question) !== QuestionHelper::class) {
  44.             $this->getHelperSet()->set($question = new QuestionHelper());
  45.         }
  46.         return $question;
  47.     }
  48.     /**
  49.      * Tries to make a path relative to the project, which prints nicer.
  50.      *
  51.      * @param string $absolutePath
  52.      *
  53.      * @return string
  54.      */
  55.     protected function makePathRelative($absolutePath)
  56.     {
  57.         $projectRootDir dirname($this->getContainer()->getParameter('kernel.root_dir'));
  58.         return str_replace($projectRootDir.'/'''realpath($absolutePath) ?: $absolutePath);
  59.     }
  60. }