-
-
Notifications
You must be signed in to change notification settings - Fork 960
[WIP/RFC] Use framework expression language service instead of custom one #2289
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the API Platform project. | ||
| * | ||
| * (c) Kévin Dunglas <dunglas@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ApiPlatform\Core\Security\Core\Authorization; | ||
|
|
||
| use Symfony\Component\ExpressionLanguage\ExpressionFunction; | ||
| use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; | ||
|
|
||
| /** | ||
| * Registers API Platform's Expression Language functions. | ||
| * | ||
| * @author Yanick Witschi <yanick.witschi@terminal42.ch> | ||
| */ | ||
| final class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface | ||
| { | ||
| public function getFunctions(): array | ||
| { | ||
| return [ | ||
| new ExpressionFunction('is_granted', function ($attributes, $object = 'null') { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it conflict with the one registered by SensioFrameworkExtraBundle?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One would just override the other (depending on the order they are called). And as far as I could see the idea was to provide the same logic, right? I mean, we could only register it if the bundle is not loaded if that makes you more comfortable? Or just tell the users to require the framework-extra-bundle if they want this function?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just want to be sure it works as intended in all cases :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should :) |
||
| return sprintf('$auth_checker->isGranted(%s, %s)', $attributes, $object); | ||
| }, function (array $variables, $attributes, $object = null) { | ||
| return $variables['auth_checker']->isGranted($attributes, $object); | ||
| }), | ||
| ]; | ||
| } | ||
| } | ||
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.
Actually,
symfony/expression-languageis inrequire-devofsymfony/security-bundle: https://github.com/symfony/symfony/blob/b5c6892911fc7454a76528cb0d4d1af4336c7413/src/Symfony/Bundle/SecurityBundle/composer.json#L42So we still need to check that the
ExpressionLanguagecomponent is actually available.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.
Are you sure?
security.expression_languagewould not be present so the alias would become invalid and as we useon-invalid="null"onapi_platform.security.resource_access_checkerthat should work. Haven't checked though.Uh oh!
There was an error while loading. Please reload this page.
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 not sure. But I think we might as well just keep them in a separate file.