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

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Bundle\GeneratorBundle\Command;
  15. use Pimcore\Bundle\GeneratorBundle\Command\Helper\QuestionHelper;
  16. use Pimcore\Bundle\GeneratorBundle\Generator\Generator;
  17. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  18. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  19. /**
  20.  * @deprecated
  21.  * Base class for generator commands.
  22.  *
  23.  * The following class is copied from \Sensio\Bundle\GeneratorBundle\Command\GeneratorCommand
  24.  */
  25. abstract class BaseGeneratorCommand extends ContainerAwareCommand
  26. {
  27.     /**
  28.      * @var Generator
  29.      */
  30.     private $generator;
  31.     abstract protected function createGenerator();
  32.     protected function getGenerator(BundleInterface $bundle null)
  33.     {
  34.         if (null === $this->generator) {
  35.             $this->generator $this->createGenerator();
  36.             $this->generator->setSkeletonDirs($this->getSkeletonDirs($bundle));
  37.         }
  38.         return $this->generator;
  39.     }
  40.     protected function getSkeletonDirs(BundleInterface $bundle null)
  41.     {
  42.         $skeletonDirs = [];
  43.         if (isset($bundle) && is_dir($dir $bundle->getPath().'/Resources/GeneratorBundle/skeleton')) {
  44.             $skeletonDirs[] = $dir;
  45.         }
  46.         if (is_dir($dir $this->getContainer()->get('kernel')->getRootdir().'/Resources/GeneratorBundle/skeleton')) {
  47.             $skeletonDirs[] = $dir;
  48.         }
  49.         $skeletonDirs[] = __DIR__.'/../Resources/skeleton';
  50.         $skeletonDirs[] = __DIR__.'/../Resources';
  51.         return $skeletonDirs;
  52.     }
  53.     protected function getQuestionHelper()
  54.     {
  55.         $question $this->getHelperSet()->get('question');
  56.         if (!$question || get_class($question) !== QuestionHelper::class) {
  57.             $this->getHelperSet()->set($question = new QuestionHelper());
  58.         }
  59.         return $question;
  60.     }
  61.     /**
  62.      * Tries to make a path relative to the project, which prints nicer.
  63.      *
  64.      * @param string $absolutePath
  65.      *
  66.      * @return string
  67.      */
  68.     protected function makePathRelative($absolutePath)
  69.     {
  70.         $projectRootDir dirname($this->getContainer()->getParameter('kernel.root_dir'));
  71.         return str_replace($projectRootDir.'/'''realpath($absolutePath) ?: $absolutePath);
  72.     }
  73. }