Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GeneratorBundle] Remove kunstmaan/sensio-generator-bundle dependency #3468

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions UPGRADE-7.3.md
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.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
108 changes: 108 additions & 0 deletions src/Kunstmaan/GeneratorBundle/Command/AbstractGeneratorCommand.php
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;
}
}
92 changes: 2 additions & 90 deletions src/Kunstmaan/GeneratorBundle/Command/GenerateAdminListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,7 +12,7 @@
/**
* @internal
*/
class GenerateAdminTestsCommand extends GeneratorCommand
class GenerateAdminTestsCommand extends AbstractGeneratorCommand
{
/**
* @return void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +14,7 @@
/**
* @internal
*/
class GenerateSearchPageCommand extends GenerateDoctrineCommand
class GenerateSearchPageCommand extends AbstractGeneratorCommand
{
/** @var DoctrineHelper */
private $doctrineHelper;
Expand Down Expand Up @@ -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');
Expand Down
6 changes: 1 addition & 5 deletions src/Kunstmaan/GeneratorBundle/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,7 +14,7 @@
/**
* @internal
*/
final class InstallCommand extends GeneratorCommand
final class InstallCommand extends AbstractGeneratorCommand
{
/**
* @var int
Expand Down Expand Up @@ -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('<info>Installing KunstmaanCms...</info>');
$outputStyle->writeln($this->getKunstmaanLogo());
Expand Down
12 changes: 2 additions & 10 deletions src/Kunstmaan/GeneratorBundle/Command/KunstmaanGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +23,7 @@
/**
* @internal
*/
abstract class KunstmaanGenerateCommand extends GenerateDoctrineCommand
abstract class KunstmaanGenerateCommand extends AbstractGeneratorCommand
{
/**
* @var CommandAssistant
Expand All @@ -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);

Expand Down Expand Up @@ -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)));
}

Expand Down
Loading