<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\ObjectManager\Command;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use App\ObjectManager\Command\Generator\Generator;
use App\ObjectManager\Command\Helper\QuestionHelper;
/**
* Description of GeneratorCommand
*
* @author Kossi GOTRI <kossi.gotri@gmail.com>
*/
abstract class GeneratorCommand extends ContainerAwareCommand {
private $generator;
// only useful for unit tests
public function setGenerator(Generator $generator) {
$this->generator = $generator;
}
abstract protected function createGenerator();
protected function getGenerator(BundleInterface $bundle = null) {
if (null === $this->generator) {
$this->generator = $this->createGenerator();
$this->generator->setSkeletonDirs($this->getSkeletonDirs($bundle));
}
return $this->generator;
}
protected function getSkeletonDirs(BundleInterface $bundle = null) {
$skeletonDirs = array();
if (isset($bundle) && is_dir($dir = $bundle->getPath() . '/Resources/SensioGeneratorBundle/skeleton')) {
$skeletonDirs[] = $dir;
}
if (is_dir($dir = $this->getContainer()->get('kernel')->getRootdir() . '/Resources/SensioGeneratorBundle/skeleton')) {
$skeletonDirs[] = $dir;
}
$skeletonDirs[] = __DIR__ . '/../Resources/skeleton';
$skeletonDirs[] = __DIR__ . '/../Resources';
return $skeletonDirs;
}
protected function getQuestionHelper() {
$question = $this->getHelperSet()->get('question');
if (!$question || get_class($question) !== 'Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper') {
$this->getHelperSet()->set($question = new QuestionHelper());
}
return $question;
}
}