diff --git a/UPGRADE-7.3.md b/UPGRADE-7.3.md
new file mode 100644
index 0000000000..921fec4dcf
--- /dev/null
+++ b/UPGRADE-7.3.md
@@ -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.
diff --git a/composer.json b/composer.json
index 90a8886281..04ce7ab5cd 100644
--- a/composer.json
+++ b/composer.json
@@ -73,7 +73,6 @@
"ruflin/elastica": "^7.0",
"behat/transliterator": "^1.3.0",
"defuse/php-encryption": "^2.2",
- "kunstmaan/sensio-generator-bundle": "^3.2",
"doctrine/collections": "^1.6",
"symfony/deprecation-contracts": "^2.5|^3.0",
"pagerfanta/doctrine-dbal-adapter": "^3.8",
diff --git a/src/Kunstmaan/GeneratorBundle/Command/AbstractGeneratorCommand.php b/src/Kunstmaan/GeneratorBundle/Command/AbstractGeneratorCommand.php
new file mode 100644
index 0000000000..a0a92ffc19
--- /dev/null
+++ b/src/Kunstmaan/GeneratorBundle/Command/AbstractGeneratorCommand.php
@@ -0,0 +1,108 @@
+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;
+ }
+}
diff --git a/src/Kunstmaan/GeneratorBundle/Command/GenerateAdminListCommand.php b/src/Kunstmaan/GeneratorBundle/Command/GenerateAdminListCommand.php
index 0988ae2468..9de5be30a8 100644
--- a/src/Kunstmaan/GeneratorBundle/Command/GenerateAdminListCommand.php
+++ b/src/Kunstmaan/GeneratorBundle/Command/GenerateAdminListCommand.php
@@ -6,19 +6,15 @@
use Kunstmaan\GeneratorBundle\Helper\EntityValidator;
use Kunstmaan\GeneratorBundle\Helper\GeneratorUtils;
use Kunstmaan\GeneratorBundle\Helper\Sf4AppBundle;
-use Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCommand;
-use Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
-use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* @internal
*/
-class GenerateAdminListCommand extends GenerateDoctrineCommand
+class GenerateAdminListCommand extends AbstractGeneratorCommand
{
/**
* @return void
@@ -53,13 +49,7 @@ protected function configure()
->setName('kuma:generate:adminlist');
}
- /**
- * @param InputInterface $input An InputInterface instance
- * @param OutputInterface $output An OutputInterface instance
- *
- * @return int
- */
- protected function execute(InputInterface $input, OutputInterface $output)
+ protected function execute(InputInterface $input, OutputInterface $output): int
{
$questionHelper = $this->getQuestionHelper();
@@ -126,84 +116,6 @@ protected function interact(InputInterface $input, OutputInterface $output)
}
}
- /**
- * @param QuestionHelper $questionHelper The question helper
- * @param InputInterface $input The command input
- * @param OutputInterface $output The command output
- * @param Bundle $bundle The bundle
- * @param string $entityClass The classname of the entity
- */
- protected function updateRouting(
- QuestionHelper $questionHelper,
- InputInterface $input,
- OutputInterface $output,
- Bundle $bundle,
- $entityClass,
- ) {
- $adminKey = $this->getContainer()->getParameter('kunstmaan_admin.admin_prefix');
- $auto = true;
- $multilang = false;
- if ($input->isInteractive()) {
- $confirmationQuestion = new ConfirmationQuestion(
- $questionHelper->getQuestion('Is it a multilanguage site', 'yes', '?'), true
- );
- $multilang = $questionHelper->ask($input, $output, $confirmationQuestion);
- $confirmationQuestion = new ConfirmationQuestion(
- $questionHelper->getQuestion('Do you want to update the routing automatically', 'yes', '?'), true
- );
- $auto = $questionHelper->ask($input, $output, $confirmationQuestion);
- }
-
- $prefix = $multilang ? '/{_locale}' : '';
-
- $code = sprintf("%s:\n", strtolower($bundle->getName()) . '_' . strtolower($entityClass) . '_admin_list');
- $code .= sprintf(" resource: '@%s/Controller/%sAdminListController.php'\n", $bundle->getName(), $entityClass);
- $code .= " type: attribute\n";
- $code .= sprintf(" prefix: %s/%s/%s/\n", $prefix, $adminKey, strtolower($entityClass));
- if ($multilang) {
- $code .= " requirements:\n";
- $code .= " _locale: \"%requiredlocales%\"\n";
- }
-
- if ($auto) {
- $file = $bundle->getPath() . '/Resources/config/routing.yml';
- $content = '';
-
- if (file_exists($file)) {
- $content = file_get_contents($file);
- } elseif (!is_dir($dir = dirname($file))) {
- mkdir($dir, 0777, true);
- }
-
- $content .= "\n";
- $content .= $code;
-
- if (false === file_put_contents($file, $content)) {
- $output->writeln(
- $questionHelper->getHelperSet()->get('formatter')->formatBlock(
- 'Failed adding the content automatically',
- 'error'
- )
- );
- } else {
- return;
- }
- }
-
- $output->writeln('Add the following to your routing.yml');
- $output->writeln('/*******************************/');
- $output->write($code);
- $output->writeln('/*******************************/');
- }
-
- /**
- * KunstmaanTestBundle_TestEntity:
- * resource: "@KunstmaanTestBundle/Controller/TestEntityAdminListController.php"
- * type: annotation
- * prefix: /{_locale}/%kunstmaan_admin.admin_prefix%/testentity/
- * requirements:
- * _locale: "%requiredlocales%"
- */
protected function createGenerator()
{
return new AdminListGenerator(GeneratorUtils::getFullSkeletonPath('adminlist'));
diff --git a/src/Kunstmaan/GeneratorBundle/Command/GenerateAdminTestsCommand.php b/src/Kunstmaan/GeneratorBundle/Command/GenerateAdminTestsCommand.php
index 1aede120d6..aef4bb6712 100644
--- a/src/Kunstmaan/GeneratorBundle/Command/GenerateAdminTestsCommand.php
+++ b/src/Kunstmaan/GeneratorBundle/Command/GenerateAdminTestsCommand.php
@@ -4,7 +4,6 @@
use Kunstmaan\GeneratorBundle\Generator\AdminTestsGenerator;
use Kunstmaan\GeneratorBundle\Helper\Sf4AppBundle;
-use Sensio\Bundle\GeneratorBundle\Command\GeneratorCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@@ -13,7 +12,7 @@
/**
* @internal
*/
-class GenerateAdminTestsCommand extends GeneratorCommand
+class GenerateAdminTestsCommand extends AbstractGeneratorCommand
{
/**
* @return void
diff --git a/src/Kunstmaan/GeneratorBundle/Command/GenerateSearchPageCommand.php b/src/Kunstmaan/GeneratorBundle/Command/GenerateSearchPageCommand.php
index 921b1bbb19..416393fcbb 100644
--- a/src/Kunstmaan/GeneratorBundle/Command/GenerateSearchPageCommand.php
+++ b/src/Kunstmaan/GeneratorBundle/Command/GenerateSearchPageCommand.php
@@ -5,7 +5,6 @@
use Kunstmaan\GeneratorBundle\Generator\SearchPageGenerator;
use Kunstmaan\GeneratorBundle\Helper\GeneratorUtils;
use Kunstmaan\GeneratorBundle\Helper\Sf4AppBundle;
-use Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCommand;
use Symfony\Bundle\MakerBundle\Doctrine\DoctrineHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -15,7 +14,7 @@
/**
* @internal
*/
-class GenerateSearchPageCommand extends GenerateDoctrineCommand
+class GenerateSearchPageCommand extends AbstractGeneratorCommand
{
/** @var DoctrineHelper */
private $doctrineHelper;
@@ -58,15 +57,7 @@ protected function configure()
->setName('kuma:generate:searchpage');
}
- /**
- * Executes the command.
- *
- * @param InputInterface $input An InputInterface instance
- * @param OutputInterface $output An OutputInterface instance
- *
- * @return int
- */
- protected function execute(InputInterface $input, OutputInterface $output)
+ protected function execute(InputInterface $input, OutputInterface $output): int
{
$questionHelper = $this->getQuestionHelper();
$questionHelper->writeSection($output, 'Search Page Generation');
diff --git a/src/Kunstmaan/GeneratorBundle/Command/InstallCommand.php b/src/Kunstmaan/GeneratorBundle/Command/InstallCommand.php
index 61b6fabcb5..11896a2a0c 100644
--- a/src/Kunstmaan/GeneratorBundle/Command/InstallCommand.php
+++ b/src/Kunstmaan/GeneratorBundle/Command/InstallCommand.php
@@ -3,8 +3,6 @@
namespace Kunstmaan\GeneratorBundle\Command;
use Kunstmaan\GeneratorBundle\Helper\CommandAssistant;
-use Sensio\Bundle\GeneratorBundle\Command\GeneratorCommand;
-use Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
@@ -16,7 +14,7 @@
/**
* @internal
*/
-final class InstallCommand extends GeneratorCommand
+final class InstallCommand extends AbstractGeneratorCommand
{
/**
* @var int
@@ -73,8 +71,6 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
{
$this->initAssistant($input, $output);
- $questionHelper = new QuestionHelper();
-
$outputStyle = new SymfonyStyle($input, $output);
$outputStyle->writeln('Installing KunstmaanCms...');
$outputStyle->writeln($this->getKunstmaanLogo());
diff --git a/src/Kunstmaan/GeneratorBundle/Command/KunstmaanGenerateCommand.php b/src/Kunstmaan/GeneratorBundle/Command/KunstmaanGenerateCommand.php
index 3c4dc9190c..bce67ea370 100644
--- a/src/Kunstmaan/GeneratorBundle/Command/KunstmaanGenerateCommand.php
+++ b/src/Kunstmaan/GeneratorBundle/Command/KunstmaanGenerateCommand.php
@@ -5,7 +5,6 @@
use Kunstmaan\GeneratorBundle\Helper\CommandAssistant;
use Kunstmaan\GeneratorBundle\Helper\GeneratorUtils;
use Kunstmaan\GeneratorBundle\Helper\Sf4AppBundle;
-use Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCommand;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -24,7 +23,7 @@
/**
* @internal
*/
-abstract class KunstmaanGenerateCommand extends GenerateDoctrineCommand
+abstract class KunstmaanGenerateCommand extends AbstractGeneratorCommand
{
/**
* @var CommandAssistant
@@ -46,10 +45,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
$this->doInteract();
}
- /**
- * @return int|null
- */
- protected function execute(InputInterface $input, OutputInterface $output)
+ protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->setInputAndOutput($input, $output);
@@ -187,10 +183,6 @@ protected function askForPrefix(?array $text = null, $namespace = null)
*/
private function convertNamespaceToSnakeCase($namespace): string
{
- if (is_null($namespace)) {
- return null;
- }
-
return str_replace('/', '_', strtolower($this->fixNamespace($namespace)));
}
diff --git a/src/Kunstmaan/GeneratorBundle/Generator/AbstractGenerator.php b/src/Kunstmaan/GeneratorBundle/Generator/AbstractGenerator.php
new file mode 100644
index 0000000000..0fec508754
--- /dev/null
+++ b/src/Kunstmaan/GeneratorBundle/Generator/AbstractGenerator.php
@@ -0,0 +1,105 @@
+
+ *
+ * @interal
+ */
+class AbstractGenerator
+{
+ private $skeletonDirs;
+ private static $output;
+
+ /**
+ * Sets an array of directories to look for templates.
+ *
+ * The directories must be sorted from the most specific to the most
+ * directory.
+ *
+ * @param array $skeletonDirs An array of skeleton dirs
+ */
+ public function setSkeletonDirs($skeletonDirs)
+ {
+ $this->skeletonDirs = is_array($skeletonDirs) ? $skeletonDirs : [$skeletonDirs];
+ }
+
+ protected function render($template, $parameters)
+ {
+ $twig = $this->getTwigEnvironment();
+
+ return $twig->render($template, $parameters);
+ }
+
+ /**
+ * Gets the twig environment that will render skeletons.
+ *
+ * @return Environment
+ */
+ protected function getTwigEnvironment()
+ {
+ return new Environment(new FilesystemLoader($this->skeletonDirs), [
+ 'debug' => true,
+ 'cache' => false,
+ 'strict_variables' => true,
+ 'autoescape' => false,
+ ]);
+ }
+
+ protected function renderFile($template, $target, $parameters)
+ {
+ self::mkdir(dirname($target));
+
+ return self::dump($target, $this->render($template, $parameters));
+ }
+
+ /**
+ * @internal
+ */
+ public static function mkdir($dir, $mode = 0777, $recursive = true)
+ {
+ if (!is_dir($dir)) {
+ mkdir($dir, $mode, $recursive);
+ self::writeln(sprintf(' created> %s', self::relativizePath($dir)));
+ }
+ }
+
+ /**
+ * @internal
+ */
+ public static function dump($filename, $content)
+ {
+ if (file_exists($filename)) {
+ self::writeln(sprintf(' updated> %s', self::relativizePath($filename)));
+ } else {
+ self::writeln(sprintf(' created> %s', self::relativizePath($filename)));
+ }
+
+ return file_put_contents($filename, $content);
+ }
+
+ private static function writeln($message)
+ {
+ if (null === self::$output) {
+ self::$output = new ConsoleOutput();
+ }
+
+ self::$output->writeln($message);
+ }
+
+ private static function relativizePath($absolutePath)
+ {
+ $relativePath = str_replace(getcwd(), '.', $absolutePath);
+
+ return is_dir($absolutePath) ? rtrim($relativePath, '/') . '/' : $relativePath;
+ }
+}
diff --git a/src/Kunstmaan/GeneratorBundle/Generator/AdminListGenerator.php b/src/Kunstmaan/GeneratorBundle/Generator/AdminListGenerator.php
index e556c5e075..a88498da71 100644
--- a/src/Kunstmaan/GeneratorBundle/Generator/AdminListGenerator.php
+++ b/src/Kunstmaan/GeneratorBundle/Generator/AdminListGenerator.php
@@ -11,7 +11,7 @@
/**
* @internal
*/
-class AdminListGenerator extends \Sensio\Bundle\GeneratorBundle\Generator\Generator
+class AdminListGenerator extends AbstractGenerator
{
/**
* @var string
diff --git a/src/Kunstmaan/GeneratorBundle/Generator/AdminTestsGenerator.php b/src/Kunstmaan/GeneratorBundle/Generator/AdminTestsGenerator.php
index 64d8eb98f7..2edf384bcf 100644
--- a/src/Kunstmaan/GeneratorBundle/Generator/AdminTestsGenerator.php
+++ b/src/Kunstmaan/GeneratorBundle/Generator/AdminTestsGenerator.php
@@ -3,7 +3,6 @@
namespace Kunstmaan\GeneratorBundle\Generator;
use Kunstmaan\GeneratorBundle\Helper\GeneratorUtils;
-use Sensio\Bundle\GeneratorBundle\Generator\Generator;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem;
@@ -15,7 +14,7 @@
*
* @interal
*/
-class AdminTestsGenerator extends Generator
+class AdminTestsGenerator extends AbstractGenerator
{
/**
* @var ContainerInterface
diff --git a/src/Kunstmaan/GeneratorBundle/Generator/FormPageGenerator.php b/src/Kunstmaan/GeneratorBundle/Generator/FormPageGenerator.php
index ba5f2559b0..994cbd0e76 100644
--- a/src/Kunstmaan/GeneratorBundle/Generator/FormPageGenerator.php
+++ b/src/Kunstmaan/GeneratorBundle/Generator/FormPageGenerator.php
@@ -102,7 +102,7 @@ public function generate(
*/
private function generatePageEntity()
{
- list($entityCode, $entityPath) = $this->generateEntity(
+ [$entityCode, $entityPath] = $this->generateEntity(
$this->bundle,
$this->entity,
$this->fields,
diff --git a/src/Kunstmaan/GeneratorBundle/Generator/KunstmaanGenerator.php b/src/Kunstmaan/GeneratorBundle/Generator/KunstmaanGenerator.php
index 9c725880fe..9b6012e62a 100644
--- a/src/Kunstmaan/GeneratorBundle/Generator/KunstmaanGenerator.php
+++ b/src/Kunstmaan/GeneratorBundle/Generator/KunstmaanGenerator.php
@@ -10,7 +10,6 @@
use Doctrine\Persistence\ManagerRegistry;
use Kunstmaan\GeneratorBundle\Helper\CommandAssistant;
use Kunstmaan\GeneratorBundle\Helper\GeneratorUtils;
-use Sensio\Bundle\GeneratorBundle\Generator\Generator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
@@ -22,7 +21,7 @@
/**
* @internal
*/
-class KunstmaanGenerator extends Generator
+class KunstmaanGenerator extends AbstractGenerator
{
/**
* @var Filesystem
diff --git a/src/Kunstmaan/GeneratorBundle/Generator/SearchPageGenerator.php b/src/Kunstmaan/GeneratorBundle/Generator/SearchPageGenerator.php
index 9e6a40b6a4..a89fa9e588 100644
--- a/src/Kunstmaan/GeneratorBundle/Generator/SearchPageGenerator.php
+++ b/src/Kunstmaan/GeneratorBundle/Generator/SearchPageGenerator.php
@@ -12,7 +12,7 @@
/**
* @internal
*/
-class SearchPageGenerator extends \Sensio\Bundle\GeneratorBundle\Generator\Generator
+class SearchPageGenerator extends AbstractGenerator
{
/**
* @var Filesystem
diff --git a/src/Kunstmaan/GeneratorBundle/Helper/Command/Validators.php b/src/Kunstmaan/GeneratorBundle/Helper/Command/Validators.php
new file mode 100644
index 0000000000..ec18ef3c92
--- /dev/null
+++ b/src/Kunstmaan/GeneratorBundle/Helper/Command/Validators.php
@@ -0,0 +1,197 @@
+
+ *
+ * @internal
+ */
+class Validators
+{
+ /**
+ * Validates that the given namespace (e.g. Acme\FooBundle) is a valid format.
+ *
+ * If $requireVendorNamespace is true, then we require you to have a vendor
+ * namespace (e.g. Acme).
+ *
+ * @param bool $requireVendorNamespace
+ *
+ * @return string
+ */
+ public static function validateBundleNamespace($namespace, $requireVendorNamespace = true)
+ {
+ if (!preg_match('/Bundle$/', $namespace)) {
+ throw new \InvalidArgumentException('The namespace must end with Bundle.');
+ }
+
+ $namespace = strtr($namespace, '/', '\\');
+ if (!preg_match('/^(?:[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\\\?)+$/', $namespace)) {
+ throw new \InvalidArgumentException('The namespace contains invalid characters.');
+ }
+
+ // validate reserved keywords
+ $reserved = self::getReservedWords();
+ foreach (explode('\\', $namespace) as $word) {
+ if (in_array(strtolower($word), $reserved)) {
+ throw new \InvalidArgumentException(sprintf('The namespace cannot contain PHP reserved words ("%s").', $word));
+ }
+ }
+
+ // validate that the namespace is at least one level deep
+ if ($requireVendorNamespace && false === strpos($namespace, '\\')) {
+ $msg = [];
+ $msg[] = sprintf('The namespace must contain a vendor namespace (e.g. "VendorName\%s" instead of simply "%s").', $namespace, $namespace);
+ $msg[] = 'If you\'ve specified a vendor namespace, did you forget to surround it with quotes (init:bundle "Acme\BlogBundle")?';
+
+ throw new \InvalidArgumentException(implode("\n\n", $msg));
+ }
+
+ return $namespace;
+ }
+
+ public static function validateBundleName($bundle)
+ {
+ if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $bundle)) {
+ throw new \InvalidArgumentException(sprintf('The bundle name %s contains invalid characters.', $bundle));
+ }
+
+ if (!preg_match('/Bundle$/', $bundle)) {
+ throw new \InvalidArgumentException('The bundle name must end with Bundle.');
+ }
+
+ return $bundle;
+ }
+
+ public static function validateControllerName($controller)
+ {
+ try {
+ self::validateEntityName($controller);
+ } catch (\InvalidArgumentException $e) {
+ throw new \InvalidArgumentException(sprintf('The controller name must contain a : ("%s" given, expecting something like AcmeBlogBundle:Post)', $controller));
+ }
+
+ return $controller;
+ }
+
+ public static function validateFormat($format)
+ {
+ if (!$format) {
+ throw new \RuntimeException('Please enter a configuration format.');
+ }
+
+ $format = strtolower($format);
+
+ // in case they typed "yaml", but ok with that
+ if ($format == 'yaml') {
+ $format = 'yml';
+ }
+
+ if (!in_array($format, ['php', 'xml', 'yml', 'annotation'])) {
+ throw new \RuntimeException(sprintf('Format "%s" is not supported.', $format));
+ }
+
+ return $format;
+ }
+
+ /**
+ * Performs basic checks in entity name.
+ *
+ * @param string $entity
+ *
+ * @return string
+ *
+ * @throws \InvalidArgumentException
+ */
+ public static function validateEntityName($entity)
+ {
+ if (!preg_match('{^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*:[a-zA-Z0-9_\x7f-\xff\\\/]+$}', $entity)) {
+ throw new \InvalidArgumentException(sprintf('The entity name isn\'t valid ("%s" given, expecting something like AcmeBlogBundle:Blog/Post)', $entity));
+ }
+
+ return $entity;
+ }
+
+ public static function getReservedWords()
+ {
+ return [
+ 'abstract',
+ 'and',
+ 'array',
+ 'as',
+ 'break',
+ 'callable',
+ 'case',
+ 'catch',
+ 'class',
+ 'clone',
+ 'const',
+ 'continue',
+ 'declare',
+ 'default',
+ 'do',
+ 'else',
+ 'elseif',
+ 'enddeclare',
+ 'endfor',
+ 'endforeach',
+ 'endif',
+ 'endswitch',
+ 'endwhile',
+ 'extends',
+ 'final',
+ 'finally',
+ 'for',
+ 'foreach',
+ 'function',
+ 'global',
+ 'goto',
+ 'if',
+ 'implements',
+ 'interface',
+ 'instanceof',
+ 'insteadof',
+ 'namespace',
+ 'new',
+ 'or',
+ 'private',
+ 'protected',
+ 'public',
+ 'static',
+ 'switch',
+ 'throw',
+ 'trait',
+ 'try',
+ 'use',
+ 'var',
+ 'while',
+ 'xor',
+ 'yield',
+ '__CLASS__',
+ '__DIR__',
+ '__FILE__',
+ '__LINE__',
+ '__FUNCTION__',
+ '__METHOD__',
+ '__NAMESPACE__',
+ '__TRAIT__',
+ '__halt_compiler',
+ 'die',
+ 'echo',
+ 'empty',
+ 'exit',
+ 'eval',
+ 'include',
+ 'include_once',
+ 'isset',
+ 'list',
+ 'require',
+ 'require_once',
+ 'return',
+ 'print',
+ 'unset',
+ ];
+ }
+}
diff --git a/src/Kunstmaan/GeneratorBundle/Helper/CommandAssistant.php b/src/Kunstmaan/GeneratorBundle/Helper/CommandAssistant.php
index 653623ab35..58b1237bc9 100644
--- a/src/Kunstmaan/GeneratorBundle/Helper/CommandAssistant.php
+++ b/src/Kunstmaan/GeneratorBundle/Helper/CommandAssistant.php
@@ -2,7 +2,6 @@
namespace Kunstmaan\GeneratorBundle\Helper;
-use Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
diff --git a/src/Kunstmaan/GeneratorBundle/Helper/GeneratorUtils.php b/src/Kunstmaan/GeneratorBundle/Helper/GeneratorUtils.php
index 67129ce44a..afa2a02c63 100644
--- a/src/Kunstmaan/GeneratorBundle/Helper/GeneratorUtils.php
+++ b/src/Kunstmaan/GeneratorBundle/Helper/GeneratorUtils.php
@@ -3,7 +3,6 @@
namespace Kunstmaan\GeneratorBundle\Helper;
use Doctrine\ORM\Mapping\ClassMetadata;
-use Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
diff --git a/src/Kunstmaan/GeneratorBundle/Helper/InputAssistant.php b/src/Kunstmaan/GeneratorBundle/Helper/InputAssistant.php
index e00cfb7625..cba7a373ca 100644
--- a/src/Kunstmaan/GeneratorBundle/Helper/InputAssistant.php
+++ b/src/Kunstmaan/GeneratorBundle/Helper/InputAssistant.php
@@ -2,8 +2,7 @@
namespace Kunstmaan\GeneratorBundle\Helper;
-use Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper;
-use Sensio\Bundle\GeneratorBundle\Command\Validators;
+use Kunstmaan\GeneratorBundle\Helper\Command\Validators;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
@@ -83,7 +82,7 @@ public function askForNamespace(?array $text = null)
}
$question = new Question($this->questionHelper->getQuestion('Bundle Namespace', $namespace), $namespace);
- $question->setValidator(['Sensio\Bundle\GeneratorBundle\Command\Validators', 'validateBundleNamespace']);
+ $question->setValidator([Validators::class, 'validateBundleNamespace']);
$question->setAutocompleterValues($namespaces);
$namespace = $this->questionHelper->ask($this->input, $this->output, $question);
@@ -221,10 +220,6 @@ public function askForPrefix(?array $text = null, $namespace = null)
*/
private function convertNamespaceToSnakeCase($namespace): string
{
- if (is_null($namespace)) {
- return null;
- }
-
return str_replace('/', '_', strtolower($this->fixNamespace($namespace)));
}
}
diff --git a/src/Kunstmaan/GeneratorBundle/Helper/QuestionHelper.php b/src/Kunstmaan/GeneratorBundle/Helper/QuestionHelper.php
new file mode 100644
index 0000000000..3ad566ea69
--- /dev/null
+++ b/src/Kunstmaan/GeneratorBundle/Helper/QuestionHelper.php
@@ -0,0 +1,59 @@
+
+ *
+ * @interal
+ */
+class QuestionHelper extends BaseQuestionHelper
+{
+ public function writeGeneratorSummary(OutputInterface $output, $errors)
+ {
+ if (!$errors) {
+ $this->writeSection($output, 'Everything is OK! Now get to work :).');
+ } else {
+ $this->writeSection($output, [
+ 'The command was not able to configure everything automatically.',
+ 'You\'ll need to make the following changes manually.',
+ ], 'error');
+
+ $output->writeln($errors);
+ }
+ }
+
+ public function getRunner(OutputInterface $output, &$errors)
+ {
+ $runner = function ($err) use ($output, &$errors) {
+ if ($err) {
+ $output->writeln('FAILED>');
+ $errors = array_merge($errors, $err);
+ } else {
+ $output->writeln('OK');
+ }
+ };
+
+ return $runner;
+ }
+
+ public function writeSection(OutputInterface $output, $text, $style = 'bg=blue;fg=white')
+ {
+ $output->writeln([
+ '',
+ $this->getHelperSet()->get('formatter')->formatBlock($text, $style, true),
+ '',
+ ]);
+ }
+
+ public function getQuestion($question, $default, $sep = ':')
+ {
+ return $default ? sprintf('%s [%s]%s ', $question, $default, $sep) : sprintf('%s%s ', $question, $sep);
+ }
+}
diff --git a/src/Kunstmaan/GeneratorBundle/composer.json b/src/Kunstmaan/GeneratorBundle/composer.json
index 76078943c7..41d3bf1a4a 100644
--- a/src/Kunstmaan/GeneratorBundle/composer.json
+++ b/src/Kunstmaan/GeneratorBundle/composer.json
@@ -18,7 +18,6 @@
"doctrine/inflector": "^1.4|^2.0",
"doctrine/data-fixtures": "^1.5",
"fakerphp/faker": "^1.15",
- "kunstmaan/sensio-generator-bundle": "^3.2",
"symfony/maker-bundle": "^1.39"
},
"require-dev": {