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

Replace $container has check with hasParameter #7769

Conversation

Buratinas
Copy link
Contributor

@Buratinas Buratinas commented Mar 18, 2022

When extensions are being loaded one by one into tmpContainer inside
vendor/symfony/dependency-injection/Compiler/MergeExtensionConfigurationPass.php
sonata_admin configuration is loaded alone, and other extension services are not present.
By replacing has check with hasParameter check we can make sure parameter exists instead of service.
Since we can easily configure extra parameter,
but to get service we would need to load most of the acl bundle extension services.

Subject

I am targeting this branch, because I'm working with this and it's the latest branch.

Closes #7768.

Changelog

### Fixed
- Improve detection of Symfony ACL bundle installation

When extensions are being loaded one by one into tmpContainer inside
`vendor/symfony/dependency-injection/Compiler/MergeExtensionConfigurationPass.php`
`sonata_admin` configuration is loaded alone, and other extension services are not present.
By replacing `has` check with `hasParameter` check we can make sure parameter exists instead of service.
Since we can easily configure extra parameter,
but to get service we would need to load most of the acl bundle extension services.
@@ -144,7 +144,7 @@ public function load(array $configs, ContainerBuilder $container): void

break;
case 'sonata.admin.security.handler.acl':
if (!$container->has('security.acl.provider')) {
if (!$container->hasParameter('security.acl.provider')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we instead check for the presence of the bundle enabled?, something like:

Suggested change
if (!$container->hasParameter('security.acl.provider')) {
if (!isset($bundles['AclBundle'])) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that actually might work better. I was checking bundles in compiler passes and extensions and it never came to my mind to simply replace this check with bundle check, although I wonder if that's the only bundle which can do ACL. I'll add it in front and I guess I can leave this as fallback since it should work with simple or statement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that the only integration we support is that bundle, We use some interfaces from there and dependencies also declared there. I wouldn't compplicate it any further, to me we should remove other checks and leave only the bundle one, wdyt @VincentLanglet ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this might be the case. If support is only with symfony/acl-bundle, then bundle check and error message change should be enough - if it only checks if bundle exists, then the message should probably not mention security.acl.provider at all, just the part with required bundle.

@Buratinas Buratinas force-pushed the replace-has-with-has-parameter-check branch from c848555 to ce87f98 Compare March 18, 2022 16:56
We only need to fail fast if:
- bundle does not exist

This means if we use AclBundle we will succeed this check.
@Buratinas Buratinas force-pushed the replace-has-with-has-parameter-check branch from ce87f98 to 9c63ee9 Compare March 19, 2022 21:20
@jordisala1991 jordisala1991 merged commit b4772fb into sonata-project:4.x Mar 19, 2022
@jordisala1991
Copy link
Member

Thank you @Buratinas

@Buratinas Buratinas deleted the replace-has-with-has-parameter-check branch March 21, 2022 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using $container->has('security.acl.provider') fails even if symfony/acl-bundle is present
3 participants