-
-
Notifications
You must be signed in to change notification settings - Fork 956
Fix. Symfony integration when starting with the micro Flex application. #1829
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
Conversation
| if (class_exists(Annotation::class)) { | ||
| // The "annotation_reader" service is only available if DoctrineBundle is loaded. | ||
| $bundles = $container->getParameter('kernel.bundles'); | ||
| if (class_exists(Annotation::class) && isset($bundles['DoctrineBundle'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this check on bundles really mandatory? I think it'd look cleaner with class_exists but maybe I'm wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's a bit weird but in theory it's possible to require "doctrine/annotation" without "doctrine/doctrine-bundle", in that case the class exists but not the service definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, can we replace this check by class_exists(DoctrineBundle::class) then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first it does look cleaner but it's not as reliable. Again, in theory, you can install a bundle with composer but not register it in Symfony's kernel. But since it's an edge case, maybe it's acceptable to simply check for class existance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd need some expert hands to answer this as I'm not qualified enough :p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @fgrandjean it should not be tested alone, since it could lead to unexpected behaviours (as the bundle may not be in the Kernel). So I guess it's better to test that the bundle is loaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm for keeping the current code too.
| $loader->load('swagger.xml'); | ||
|
|
||
| if ($config['enable_swagger_ui']) { | ||
| $bundles = $container->getParameter('kernel.bundles'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you really need the variable $bundles ?
|
|
||
| $loader->load('graphql.xml'); | ||
|
|
||
| $bundles = $container->getParameter('kernel.bundles'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you really need the variable $bundles ?
| if (class_exists(Annotation::class)) { | ||
| // The "annotation_reader" service is only available if DoctrineBundle is loaded. | ||
| $bundles = $container->getParameter('kernel.bundles'); | ||
| if (class_exists(Annotation::class) && isset($bundles['DoctrineBundle'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm for keeping the current code too.
|
|
||
| if (class_exists(Annotation::class)) { | ||
| // The "annotation_reader" service is only available if DoctrineBundle is loaded. | ||
| $bundles = $container->getParameter('kernel.bundles'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$bundles is already defined here: https://github.com/fgrandjean/core/blob/a6bb41d21f37898d80daae52336418e5310d4daf/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php#L118
You can just pass it as parameter of all register* methods.
|
|
||
| if ($config['enable_swagger_ui']) { | ||
| $bundles = $container->getParameter('kernel.bundles'); | ||
| if ($config['enable_swagger_ui'] && isset($bundles['TwigBundle'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe should we just throw if enable_swagger_ui is true but Twig isn't available. It would be easier to debug (the exception's message should recommend to install twig-bundle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value of enable_swagger_ui can be false if twig isn't available btw (in the Configuration class). As you'll not be able to access to the installed bundle list in this class, you can fallback on checking if class_exists(TwigBundle::class).
|
|
||
| $loader->load('graphql.xml'); | ||
|
|
||
| if (isset($bundles['TwigBundle'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks wrong to me. It means that you can't get GraphQL support without Twig.
As for Swagger UI, you should throw if api_platform.graphql.graphiql.enabled is true but Twig isn't installed.
| @@ -0,0 +1,21 @@ | |||
| <?xml version="1.0" ?> | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be reverted. This action isn't here for GraphiQL in the first place. It is the main GraphQL entrypoint.
Throw exception when graphql is turn on but Twig is missing. Fixing tests to cover exceptions.
|
|
||
| if (class_exists(Annotation::class)) { | ||
| // The "annotation_reader" service is only available if DoctrineBundle is loaded. | ||
| if (class_exists(Annotation::class) && isset($bundles['DoctrineBundle'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use
$container->hasExtension('doctrine')There is no need to pass the $bundles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, they're not strictly the same thing. But we can safely assume that the doctrine extension must be registered if DoctrineBundle is loaded.
WDYT @dunglas? I think we can simplify the existing code too...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me it's mostly the same thing, except that we check for TwigBundle using isset($bundles['TwigBundle']) it made sens to do it the same way for doctrine to keep the code easy to read. But I let @dunglas decide.
The goal here is to make it failsafe to install api-platform/core on a symfony/skeleton project.
It remove hardcoded dependencies for doctrine/doctrine-bundle and symfony/twig-bundle.
Corresponding features get toggle back on when the package are added to the project.