From 673c3a5a348ccdcd0cff43e00c427ac0f881ab9e Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:28:45 -0400 Subject: [PATCH] minor #1514 replace Bundle with the new AbstractBundle class * refactor in new generate_final_* params * is github still complaining about a merge conflict * php-cs-fixer it up * minor disclaimer for php-cs-fixer config * move docs to project level dir instead of in src/Resources * remove unused files * add missing extension alias * fix doctrine ns config * fix bundled php-cs-fixer config path --- .symfony.bundle.yaml | 2 +- _docs_build/build.php | 2 +- {src/Resources/config => config}/makers.xml | 0 .../config => config}/php-cs-fixer.config.php | 8 +++ {src/Resources/config => config}/services.xml | 0 {src/Resources/doc => docs}/index.rst | 0 src/DependencyInjection/Configuration.php | 34 ----------- src/DependencyInjection/MakerExtension.php | 58 ------------------- src/MakerBundle.php | 45 +++++++++++++- src/Util/TemplateLinter.php | 2 +- 10 files changed, 54 insertions(+), 97 deletions(-) rename {src/Resources/config => config}/makers.xml (100%) rename {src/Resources/config => config}/php-cs-fixer.config.php (67%) rename {src/Resources/config => config}/services.xml (100%) rename {src/Resources/doc => docs}/index.rst (100%) delete mode 100644 src/DependencyInjection/Configuration.php delete mode 100644 src/DependencyInjection/MakerExtension.php diff --git a/.symfony.bundle.yaml b/.symfony.bundle.yaml index a9c304aee..5c0f1017a 100644 --- a/.symfony.bundle.yaml +++ b/.symfony.bundle.yaml @@ -2,5 +2,5 @@ branches: ["main"] maintained_branches: ["main"] -doc_dir: "src/Resources/doc" +doc_dir: "docs" diff --git a/_docs_build/build.php b/_docs_build/build.php index 20bec5ad2..94130918a 100755 --- a/_docs_build/build.php +++ b/_docs_build/build.php @@ -30,7 +30,7 @@ $outputDir = __DIR__.'/output'; $buildConfig = (new BuildConfig()) ->setSymfonyVersion('7.1') - ->setContentDir(__DIR__.'/../src/Resources/doc') + ->setContentDir(__DIR__.'/../docs') ->setOutputDir($outputDir) ->setImagesDir(__DIR__.'/output/_images') ->setImagesPublicPrefix('_images') diff --git a/src/Resources/config/makers.xml b/config/makers.xml similarity index 100% rename from src/Resources/config/makers.xml rename to config/makers.xml diff --git a/src/Resources/config/php-cs-fixer.config.php b/config/php-cs-fixer.config.php similarity index 67% rename from src/Resources/config/php-cs-fixer.config.php rename to config/php-cs-fixer.config.php index 9b5ee2826..59acf276b 100644 --- a/src/Resources/config/php-cs-fixer.config.php +++ b/config/php-cs-fixer.config.php @@ -9,6 +9,14 @@ * file that was distributed with this source code. */ +/* + * This PHP-CS-Fixer config file is used by the TemplateLinter for userland + * code when say make:controller is run. If a user does not have a php-cs-fixer + * config file, this one is used on the generated PHP files. + * + * It should not be confused by the root level .php-cs-fixer.dist.php config + * which is used to maintain the MakerBundle codebase itself. + */ return (new PhpCsFixer\Config()) ->setRules([ '@Symfony' => true, diff --git a/src/Resources/config/services.xml b/config/services.xml similarity index 100% rename from src/Resources/config/services.xml rename to config/services.xml diff --git a/src/Resources/doc/index.rst b/docs/index.rst similarity index 100% rename from src/Resources/doc/index.rst rename to docs/index.rst diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php deleted file mode 100644 index 15c718318..000000000 --- a/src/DependencyInjection/Configuration.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\MakerBundle\DependencyInjection; - -use Symfony\Component\Config\Definition\Builder\TreeBuilder; -use Symfony\Component\Config\Definition\ConfigurationInterface; - -class Configuration implements ConfigurationInterface -{ - public function getConfigTreeBuilder(): TreeBuilder - { - $treeBuilder = new TreeBuilder('maker'); - $rootNode = $treeBuilder->getRootNode(); - - $rootNode - ->children() - ->scalarNode('root_namespace')->defaultValue('App')->end() - ->booleanNode('generate_final_classes')->defaultTrue()->end() - ->booleanNode('generate_final_entities')->defaultFalse()->end() - ->end() - ; - - return $treeBuilder; - } -} diff --git a/src/DependencyInjection/MakerExtension.php b/src/DependencyInjection/MakerExtension.php deleted file mode 100644 index 1de775bff..000000000 --- a/src/DependencyInjection/MakerExtension.php +++ /dev/null @@ -1,58 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\MakerBundle\DependencyInjection; - -use Symfony\Bundle\MakerBundle\DependencyInjection\CompilerPass\MakeCommandRegistrationPass; -use Symfony\Bundle\MakerBundle\MakerInterface; -use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; - -/** - * This is the class that loads and manages your bundle configuration. - * - * @see http://symfony.com/doc/current/cookbook/bundles/extension.html - */ -class MakerExtension extends Extension -{ - public function load(array $configs, ContainerBuilder $container): void - { - $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('services.xml'); - $loader->load('makers.xml'); - - $configuration = $this->getConfiguration($configs, $container); - $config = $this->processConfiguration($configuration, $configs); - - $rootNamespace = trim($config['root_namespace'], '\\'); - - $autoloaderFinderDefinition = $container->getDefinition('maker.autoloader_finder'); - $autoloaderFinderDefinition->replaceArgument(0, $rootNamespace); - - $makeCommandDefinition = $container->getDefinition('maker.generator'); - $makeCommandDefinition->replaceArgument(1, $rootNamespace); - - $doctrineHelperDefinition = $container->getDefinition('maker.doctrine_helper'); - $doctrineHelperDefinition->replaceArgument(0, $rootNamespace.'\\Entity'); - - $componentGeneratorDefinition = $container->getDefinition('maker.template_component_generator'); - $componentGeneratorDefinition - ->replaceArgument(0, $config['generate_final_classes']) - ->replaceArgument(1, $config['generate_final_entities']) - ->replaceArgument(2, $rootNamespace) - ; - - $container->registerForAutoconfiguration(MakerInterface::class) - ->addTag(MakeCommandRegistrationPass::MAKER_TAG); - } -} diff --git a/src/MakerBundle.php b/src/MakerBundle.php index 427e2103c..42516aec8 100644 --- a/src/MakerBundle.php +++ b/src/MakerBundle.php @@ -14,16 +14,57 @@ use Symfony\Bundle\MakerBundle\DependencyInjection\CompilerPass\MakeCommandRegistrationPass; use Symfony\Bundle\MakerBundle\DependencyInjection\CompilerPass\RemoveMissingParametersPass; use Symfony\Bundle\MakerBundle\DependencyInjection\CompilerPass\SetDoctrineAnnotatedPrefixesPass; +use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\HttpKernel\Bundle\Bundle; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\HttpKernel\Bundle\AbstractBundle; /** * @author Javier Eguiluz * @author Ryan Weaver */ -class MakerBundle extends Bundle +class MakerBundle extends AbstractBundle { + protected string $extensionAlias = 'maker'; + + public function configure(DefinitionConfigurator $definition): void + { + $definition->rootNode() + ->children() + ->scalarNode('root_namespace')->defaultValue('App')->end() + ->booleanNode('generate_final_classes')->defaultTrue()->end() + ->booleanNode('generate_final_entities')->defaultFalse()->end() + ->end() + ; + } + + public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void + { + $container->import('../config/services.xml'); + $container->import('../config/makers.xml'); + + $rootNamespace = trim($config['root_namespace'], '\\'); + + $container->services() + ->get('maker.autoloader_finder') + ->arg(0, $rootNamespace) + ->get('maker.generator') + ->arg(1, $rootNamespace) + ->get('maker.doctrine_helper') + ->arg(0, \sprintf('%s\\Entity', $rootNamespace)) + ->get('maker.template_component_generator') + ->arg(0, $config['generate_final_classes']) + ->arg(1, $config['generate_final_entities']) + ->arg(2, $rootNamespace) + ; + + $builder + ->registerForAutoconfiguration(MakerInterface::class) + ->addTag(MakeCommandRegistrationPass::MAKER_TAG) + ; + } + public function build(ContainerBuilder $container): void { // add a priority so we run before the core command pass diff --git a/src/Util/TemplateLinter.php b/src/Util/TemplateLinter.php index e6bb70328..19907938d 100644 --- a/src/Util/TemplateLinter.php +++ b/src/Util/TemplateLinter.php @@ -145,7 +145,7 @@ private function setConfig(): void // No config provided and no project dist config - use our config if (null === $this->phpCsFixerConfigPath) { - $this->phpCsFixerConfigPath = \dirname(__DIR__).'/Resources/config/php-cs-fixer.config.php'; + $this->phpCsFixerConfigPath = \sprintf('%s/config/php-cs-fixer.config.php', \dirname(__DIR__, 2)); return; }