8000 [Workflow] Override guard listener class by ochretien · Pull Request #29751 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Workflow] Override guard listener class #29751

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

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[Workflow] Added inheritance to 'GuardListener'
  • Loading branch information
ochretien committed Jan 3, 2019
commit b97ef817280e30869738b5628537c8fba4edea92
1 change: 1 addition & 0 deletions src/Symfony/Component/Workflow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CHANGELOG
* Added support for `Event::getWorkflowName()` for "announce" events.
* Added `workflow.completed` events which are fired after a transition is completed.
* Added `guard_listener` configuration option along with `workflow.guard_listener` parameter.
* Added inheritance to `GuardListener`.

3.3.0
-----
Expand Down
18 changes: 9 additions & 9 deletions src/Symfony/Component/Workflow/EventListener/GuardListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
*/
class GuardListener
{
private $configuration;
private $expressionLanguage;
private $tokenStorage;
private $authorizationChecker;
private $trustResolver;
private $roleHierarchy;
private $validator;
protected $configuration;
Copy link
Member

Choose a reason for hiding this comment

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

That's a no-go: we strongly favor private properties because it helps maintenance a lot.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback. So as I understand it, it is preferable to create my own new class completely override the listener.guard services declaration.

Copy link
Member

Choose a reason for hiding this comment

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

yes - you can decorate the core listener if it serves your purpose, but only via composition, ie using its public API.

Copy link
Author

Choose a reason for hiding this comment

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

Since there is a no-go on changing the GuardListener properties visibility and there is other ways to serve my purpose, it seems this pull request can be closed

protected $expressionLanguage;
protected $tokenStorage;
protected $authorizationChecker;
protected $trustResolver;
protected $roleHierarchy;
protected $validator;

public function __construct(array $configuration, ExpressionLanguage $expressionLanguage, TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker, AuthenticationTrustResolverInterface $trustResolver, RoleHierarchyInterface $roleHierarchy = null, ValidatorInterface $validator = null)
{
Expand Down Expand Up @@ -62,15 +62,15 @@ public function onTransition(GuardEvent $event, $eventName)
}
}

private function validateGuardExpression(GuardEvent $event, $expression)
protected function validateGuardExpression(GuardEvent $event, $expression)
{
if (!$this->expressionLanguage->evaluate($expression, $this->getVariables($event))) {
$event->setBlocked(true);
}
}

// code should be sync with Symfony\Component\Security\Core\Authorization\Voter\ExpressionVoter
private function getVariables(GuardEvent $event)
protected function getVariables(GuardEvent $event)
{
$token = $this->tokenStorage->getToken();

Expand Down
0