From 6f02865ceaf1fc4b5ce752ba35cd6bb7dd7fee82 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Fri, 13 Sep 2024 07:58:27 -0400 Subject: [PATCH 1/9] refactor in new generate_final_* params --- {src/Resources/config => config}/makers.xml | 3 + .../config => config}/php-cs-fixer.config.php | 0 {src/Resources/config => config}/services.xml | 0 src/DependencyInjection/Configuration.php | 34 ----------- src/DependencyInjection/MakerExtension.php | 58 ------------------- src/MakerBundle.php | 42 +++++++++++++- src/Resources/config/maker.xml | 1 + 7 files changed, 45 insertions(+), 93 deletions(-) rename {src/Resources/config => config}/makers.xml (99%) rename {src/Resources/config => config}/php-cs-fixer.config.php (100%) rename {src/Resources/config => config}/services.xml (100%) create mode 100644 src/Resources/config/maker.xml diff --git a/src/Resources/config/makers.xml b/config/makers.xml similarity index 99% rename from src/Resources/config/makers.xml rename to config/makers.xml index ad7d45483..691df6715 100644 --- a/src/Resources/config/makers.xml +++ b/config/makers.xml @@ -1,5 +1,8 @@ + + + diff --git a/src/Resources/config/php-cs-fixer.config.php b/config/php-cs-fixer.config.php similarity index 100% rename from src/Resources/config/php-cs-fixer.config.php rename to config/php-cs-fixer.config.php 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/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 15c718318..e69de29bb 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -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 index 1de775bff..e69de29bb 100644 --- a/src/DependencyInjection/MakerExtension.php +++ b/src/DependencyInjection/MakerExtension.php @@ -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..0cc0277b0 100644 --- a/src/MakerBundle.php +++ b/src/MakerBundle.php @@ -14,16 +14,56 @@ 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\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\HttpKernel\Bundle\AbstractBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; /** * @author Javier Eguiluz * @author Ryan Weaver */ -class MakerBundle extends Bundle +class MakerBundle extends AbstractBundle { + 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, $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/Resources/config/maker.xml b/src/Resources/config/maker.xml new file mode 100644 index 000000000..652d87e48 --- /dev/null +++ b/src/Resources/config/maker.xml @@ -0,0 +1 @@ +This is the old maker.xml... why is github complaining abaout a merge conflict.... From 0651945a8939f09b3a4a039b6d7db5738efeda6e Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 17 Apr 2024 06:15:29 -0400 Subject: [PATCH 2/9] is github still complaining about a merge conflict --- config/makers.xml | 3 --- src/Resources/config/maker.xml | 1 - 2 files changed, 4 deletions(-) delete mode 100644 src/Resources/config/maker.xml diff --git a/config/makers.xml b/config/makers.xml index 691df6715..ad7d45483 100644 --- a/config/makers.xml +++ b/config/makers.xml @@ -1,8 +1,5 @@ - - - diff --git a/src/Resources/config/maker.xml b/src/Resources/config/maker.xml deleted file mode 100644 index 652d87e48..000000000 --- a/src/Resources/config/maker.xml +++ /dev/null @@ -1 +0,0 @@ -This is the old maker.xml... why is github complaining abaout a merge conflict.... From 9cde4bee887f812d53b9636f94afb932250c4918 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 17 Apr 2024 06:21:58 -0400 Subject: [PATCH 3/9] php-cs-fixer it up --- src/MakerBundle.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/MakerBundle.php b/src/MakerBundle.php index 0cc0277b0..3e6673a1b 100644 --- a/src/MakerBundle.php +++ b/src/MakerBundle.php @@ -19,7 +19,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symfony\Component\HttpKernel\Bundle\AbstractBundle; -use Symfony\Component\HttpKernel\Bundle\Bundle; /** * @author Javier Eguiluz From ff4bc460896b7abdc569b5c5514c45a0d5865b21 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Fri, 27 Sep 2024 01:50:50 -0400 Subject: [PATCH 4/9] minor disclaimer for php-cs-fixer config --- config/php-cs-fixer.config.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/config/php-cs-fixer.config.php b/config/php-cs-fixer.config.php index 9b5ee2826..59acf276b 100644 --- a/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, From f05746a4f5e040f49ed5d3f5fbf9529106f28541 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Fri, 27 Sep 2024 01:54:57 -0400 Subject: [PATCH 5/9] move docs to project level dir instead of in src/Resources --- .symfony.bundle.yaml | 2 +- _docs_build/build.php | 2 +- {src/Resources/doc => docs}/index.rst | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename {src/Resources/doc => docs}/index.rst (100%) 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/doc/index.rst b/docs/index.rst similarity index 100% rename from src/Resources/doc/index.rst rename to docs/index.rst From 676a2df449ee9e3a34ee310df0953fe21ac228af Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Fri, 27 Sep 2024 02:31:46 -0400 Subject: [PATCH 6/9] remove unused files --- src/DependencyInjection/Configuration.php | 0 src/DependencyInjection/MakerExtension.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/DependencyInjection/Configuration.php delete mode 100644 src/DependencyInjection/MakerExtension.php diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/DependencyInjection/MakerExtension.php b/src/DependencyInjection/MakerExtension.php deleted file mode 100644 index e69de29bb..000000000 From b9031caf00cff3efcb5f2de97f8e850baefb4896 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Fri, 27 Sep 2024 05:13:17 -0400 Subject: [PATCH 7/9] add missing extension alias --- src/MakerBundle.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/MakerBundle.php b/src/MakerBundle.php index 3e6673a1b..d51e8b32a 100644 --- a/src/MakerBundle.php +++ b/src/MakerBundle.php @@ -26,6 +26,8 @@ */ class MakerBundle extends AbstractBundle { + protected string $extensionAlias = 'maker'; + public function configure(DefinitionConfigurator $definition): void { $definition->rootNode() From 36f9f21bac44068ae3ac63c4c4b31d56382c0c8e Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Fri, 27 Sep 2024 05:43:06 -0400 Subject: [PATCH 8/9] fix doctrine ns config --- src/MakerBundle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MakerBundle.php b/src/MakerBundle.php index d51e8b32a..42516aec8 100644 --- a/src/MakerBundle.php +++ b/src/MakerBundle.php @@ -52,7 +52,7 @@ public function loadExtension(array $config, ContainerConfigurator $container, C ->get('maker.generator') ->arg(1, $rootNamespace) ->get('maker.doctrine_helper') - ->arg(0, $rootNamespace) + ->arg(0, \sprintf('%s\\Entity', $rootNamespace)) ->get('maker.template_component_generator') ->arg(0, $config['generate_final_classes']) ->arg(1, $config['generate_final_entities']) From 91982c11c72eea21522975b66dc8c30e1374981a Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Fri, 27 Sep 2024 05:52:19 -0400 Subject: [PATCH 9/9] fix bundled php-cs-fixer config path --- src/Util/TemplateLinter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; }