-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3468 from acrobat/remove-sensio-generator-dependency
[GeneratorBundle] Remove kunstmaan/sensio-generator-bundle dependency
- Loading branch information
Showing
20 changed files
with
491 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
UPGRADE FROM 7.2 to 7.3 | ||
======================== | ||
|
||
GeneratorBundle | ||
----------- | ||
|
||
- The `kunstmaan/sensio-generator-bundle` dependency is removed, if you still need it in your project, you can install it manually. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/Kunstmaan/GeneratorBundle/Command/AbstractGeneratorCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\GeneratorBundle\Command; | ||
|
||
use Kunstmaan\GeneratorBundle\Generator\AbstractGenerator; | ||
use Kunstmaan\GeneratorBundle\Helper\QuestionHelper; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\HttpKernel\Bundle\BundleInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
abstract class AbstractGeneratorCommand extends Command | ||
{ | ||
/** | ||
* @var ContainerInterface|null | ||
*/ | ||
private $container; | ||
|
||
/** | ||
* @var AbstractGenerator | ||
*/ | ||
private $generator; | ||
|
||
// only useful for unit tests | ||
public function setGenerator(AbstractGenerator $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 = []; | ||
|
||
if (isset($bundle) && is_dir($dir = $bundle->getPath() . '/Resources/SensioGeneratorBundle/skeleton')) { | ||
$skeletonDirs[] = $dir; | ||
} | ||
|
||
if (is_dir($dir = $this->getContainer()->get('kernel')->getProjectDir() . '/app/Resources/SensioGeneratorBundle/skeleton')) { | ||
$skeletonDirs[] = $dir; | ||
} | ||
|
||
if (is_dir($dir = $this->getContainer()->get('kernel')->getProjectDir() . '/templates/bundles/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) !== QuestionHelper::class) { | ||
$this->getHelperSet()->set($question = new QuestionHelper()); | ||
} | ||
|
||
return $question; | ||
} | ||
|
||
/** | ||
* Tries to make a path relative to the project, which prints nicer. | ||
* | ||
* @param string $absolutePath | ||
* | ||
* @return string | ||
*/ | ||
protected function makePathRelative($absolutePath) | ||
{ | ||
$projectRootDir = dirname($this->getContainer()->getParameter('kernel.root_dir')); | ||
|
||
return str_replace($projectRootDir . '/', '', realpath($absolutePath) ?: $absolutePath); | ||
} | ||
|
||
/** | ||
* @return ContainerInterface | ||
* | ||
* @throws \LogicException | ||
*/ | ||
protected function getContainer() | ||
{ | ||
if (null === $this->container) { | ||
$application = $this->getApplication(); | ||
if (null === $application) { | ||
throw new \LogicException('The container cannot be retrieved as the application instance is not yet set.'); | ||
} | ||
|
||
$this->container = $application->getKernel()->getContainer(); | ||
} | ||
|
||
return $this->container; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.