Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit edd1cb4

Browse files
committed
feature #51484 [Workflow] deprecate GuardEvent::getContext method (hhamon)
This PR was merged into the 6.4 branch. Discussion ---------- [Workflow] deprecate `GuardEvent::getContext` method | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | ~ | License | MIT | Doc PR | ~ As discussed with `@lyrixx`, this method is confusing as the context given as the 3rd argument to the `WorflowInterface::appy()` method is never passed along to the guard events. According to `@lyrixx`, the guard listeners must take any decisions based on the subject itself and not on the given contextual data (which are supposed to remain metadata). As a consequence, calling the `getContext` method on a `GuardEvent` object always returns an empty context. To prevent confusion and lower the BC breakage in 7.x, we advocate for deprecating this method in 6.4 and make it throw an exception in 7.0. Application codes should not call this method anyway as it always returns an empty array. EDIT: a second approach in Symfony 7.x is to remove the `getContext` method from the base abstract class and reimplement it as a dedicated trait that is used by all the other event classes except `GuardEvent`. This approach is probably a bit cleaner as the method will completly be dropped from the `GuardEvent` class scope. Any thoughts? Commits ------- 985b9db [Workflow] deprecate `GuardEvent::getContext` method
2 parents 8141036 + 985b9db commit edd1cb4

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

UPGRADE-6.4.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,8 @@ Validator
162162
* Deprecate `ValidatorBuilder::enableAnnotationMapping()`, use `ValidatorBuilder::enableAttributeMapping()` instead
163163
* Deprecate `ValidatorBuilder::disableAnnotationMapping()`, use `ValidatorBuilder::disableAttributeMapping()` instead
164164
* Deprecate `AnnotationLoader`, use `AttributeLoader` instead
165+
166+
Workflow
167+
--------
168+
169+
* Deprecate `GuardEvent::getContext()` method that will be removed in 7.0

src/Symfony/Component/Workflow/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* Add a profiler
1111
* Add support for multiline descriptions in PlantUML diagrams
1212
* Add PHP attributes to register listeners and guards
13+
* Deprecate `GuardEvent::getContext()` method that will be removed in 7.0
1314

1415
6.2
1516
---

src/Symfony/Component/Workflow/Event/GuardEvent.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ public function __construct(object $subject, Marking $marking, Transition $trans
3232
$this->transitionBlockerList = new TransitionBlockerList();
3333
}
3434

35+
public function getContext(): array
36+
{
37+
trigger_deprecation('symfony/workflow', '6.4', 'The %s::getContext() method is deprecated and will be removed in 7.0. You should no longer call this method as it always returns an empty array when invoked within a guard listener.', __CLASS__);
38+
39+
return parent::getContext();
40+
}
41+
3542
public function getTransition(): Transition
3643
{
3744
return parent::getTransition();

0 commit comments

Comments
 (0)