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

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