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

[FrameworkBundle] Run the ResolveFactoryClassPass when lint:container builds the container from a dump #50988

Merged
merged 1 commit into from
Jul 16, 2023

Conversation

MatTheCat
Copy link
Contributor

@MatTheCat MatTheCat commented Jul 15, 2023

Q A
Branch? 6.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #50622
License MIT
Doc PR N/A

#49665 replaced the factory node by a constructor attribute in the XML and YAML dumper when the factory’s class is the same as the definition’s. The corresponding loader then creates a definition where the factory class is null.

As the ResolveFactoryClassPass will not run when the lint:container command builds the container from an XML dump, such factories would make ContainerBuilder::createService crash. This PR adds this compiler pass to the list.

@lugosium
Copy link

I confirm your PR fix the issue 👍 🙏

Thanks a lot.

@nicolas-grekas
Copy link
Member

Did you consider enabling the pass on the command? That'd make more sense to me because if we do this, then we should do the same in PHP dumper, and the pass becomes useless. Also, this misses the check for $class that the pass has. WDYT ?

@MatTheCat
Copy link
Contributor Author

TBH I didn’t consider updating the command because it looks like it must work without any compiler pass.

then we should do the same in PHP dumper

I may have missed something because I don’t understand why 🤔

@nicolas-grekas
Copy link
Member

it looks like it must work without any compiler pass.

It never did before we introduced ResolveFactoryClassPass so I don't think so.

@MatTheCat
Copy link
Contributor Author

Is this what you’re asking for?

diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php
--- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php	(revision 6f2e603c176724873f92942ea7461150d0e32040)
+++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php	(date 1689424425782)
@@ -20,6 +20,7 @@
 use Symfony\Component\Console\Style\SymfonyStyle;
 use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
 use Symfony\Component\DependencyInjection\Compiler\PassConfig;
+use Symfony\Component\DependencyInjection\Compiler\ResolveFactoryClassPass;
 use Symfony\Component\DependencyInjection\Container;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
@@ -120,7 +121,7 @@
             }
 
             $container->getCompilerPassConfig()->setBeforeOptimizationPasses([]);
-            $container->getCompilerPassConfig()->setOptimizationPasses([]);
+            $container->getCompilerPassConfig()->setOptimizationPasses([new ResolveFactoryClassPass()]);
             $container->getCompilerPassConfig()->setBeforeRemovingPasses([]);
         }
 

It feels weird needing this particular pass to build the container from a dump.

@MatTheCat MatTheCat changed the base branch from 6.3 to 5.4 July 15, 2023 15:00
@MatTheCat MatTheCat force-pushed the null_factory_class_service branch 3 times, most recently from fdd8a62 to d8afb57 Compare July 15, 2023 15:54
@MatTheCat MatTheCat changed the base branch from 5.4 to 6.3 July 15, 2023 15:54
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jul 15, 2023

Yes that's what I mean. Dealing with th dumped XML requires special care, this makes sense to me. At least more than making the pass half-needeed. I prefer keeping the symmetry between the dumped container and a compiled container builder.

@MatTheCat MatTheCat changed the title [DependencyInjection] Handle null factory class in ContainerBuilder::createService [FrameworkBundle] Run the ResolveFactoryClassPass when lint:container builds the container from a dump Jul 15, 2023
@MatTheCat
Copy link
Contributor Author

Okay PR updated, thanks for the feedback 🙏

@carsonbot carsonbot changed the title [FrameworkBundle] Run the ResolveFactoryClassPass when lint:container builds the container from a dump [DependencyInjection] Run the ResolveFactoryClassPass when lint:container builds the container from a dump Jul 16, 2023
@nicolas-grekas
Copy link
Member

Thank you @MatTheCat.

@nicolas-grekas nicolas-grekas merged commit 359fbc1 into symfony:6.3 Jul 16, 2023
8 of 9 checks passed
@MatTheCat MatTheCat changed the title [DependencyInjection] Run the ResolveFactoryClassPass when lint:container builds the container from a dump [FrameworkBundle] Run the ResolveFactoryClassPass when lint:container builds the container from a dump Jul 16, 2023
@MatTheCat MatTheCat deleted the null_factory_class_service branch July 16, 2023 16:51
@fabpot fabpot mentioned this pull request Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants