Skip to content

Commit 16b7e82

Browse files
committed
Remove GuardEvent::getContext() method and add HasContextTrait trait
1 parent d510239 commit 16b7e82

File tree

11 files changed

+107
-10
lines changed

11 files changed

+107
-10
lines changed

UPGRADE-7.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ Workflow
490490
--------
491491

492492
* Require explicit argument when calling `Definition::setInitialPlaces()`
493+
* `GuardEvent::getContext()` method has been removed. Method was not supposed to be called within guard event listeners as it always returned an empty array anyway.
493494

494495
Yaml
495496
----

src/Symfony/Component/Workflow/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ CHANGELOG
55
---
66

77
* Require explicit argument when calling `Definition::setInitialPlaces()`
8+
* `GuardEvent::getContext()` method has been removed. Method was not supposed to be called within guard event listeners as it always returned an empty array anyway.
9+
* Add internal `HasContextTrait` trait used by all workflow event classes except by `GuardEvent` class
810

911
6.4
1012
---

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111

1212
namespace Symfony\Component\Workflow\Event;
1313

14+
use Symfony\Component\Workflow\Marking;
15+
use Symfony\Component\Workflow\Transition;
16+
use Symfony\Component\Workflow\WorkflowInterface;
17+
1418
final class AnnounceEvent extends Event
1519
{
20+
use HasContextTrait;
21+
22+
public function __construct(object $subject, Marking $marking, ?Transition $transition = null, ?WorkflowInterface $workflow = null, array $context = [])
23+
{
24+
parent::__construct($subject, $marking, $transition, $workflow);
25+
26+
$this->context = $context;
27+
}
1628
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111

1212
namespace Symfony\Component\Workflow\Event;
1313

14+
use Symfony\Component\Workflow\Marking;
15+
use Symfony\Component\Workflow\Transition;
16+
use Symfony\Component\Workflow\WorkflowInterface;
17+
1418
final class CompletedEvent extends Event
1519
{
20+
use HasContextTrait;
21+
22+
public function __construct(object $subject, Marking $marking, ?Transition $transition = null, ?WorkflowInterface $workflow = null, array $context = [])
23+
{
24+
parent::__construct($subject, $marking, $transition, $workflow);
25+
26+
$this->context = $context;
27+
}
1628
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111

1212
namespace Symfony\Component\Workflow\Event;
1313

14+
use Symfony\Component\Workflow\Marking;
15+
use Symfony\Component\Workflow\Transition;
16+
use Symfony\Component\Workflow\WorkflowInterface;
17+
1418
final class EnterEvent extends Event
1519
{
20+
use HasContextTrait;
21+
22+
public function __construct(object $subject, Marking $marking, ?Transition $transition = null, ?WorkflowInterface $workflow = null, array $context = [])
23+
{
24+
parent::__construct($subject, $marking, $transition, $workflow);
25+
26+
$this->context = $context;
27+
}
1628
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111

1212
namespace Symfony\Component\Workflow\Event;
1313

14+
use Symfony\Component\Workflow\Marking;
15+
use Symfony\Component\Workflow\Transition;
16+
use Symfony\Component\Workflow\WorkflowInterface;
17+
1418
final class EnteredEvent extends Event
1519
{
20+
use HasContextTrait;
21+
22+
public function __construct(object $subject, Marking $marking, ?Transition $transition = null, ?WorkflowInterface $workflow = null, array $context = [])
23+
{
24+
parent::__construct($subject, $marking, $transition, $workflow);
25+
26+
$this->context = $context;
27+
}
1628
}

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,17 @@
2323
*/
2424
class Event extends BaseEvent
2525
{
26-
protected array $context;
27-
2826
private object $subject;
2927
private Marking $marking;
3028
private ?Transition $transition;
3129
private ?WorkflowInterface $workflow;
3230

33-
public function __construct(object $subject, Marking $marking, Transition $transition = null, WorkflowInterface $workflow = null, array $context = [])
31+
public function __construct(object $subject, Marking $marking, ?Transition $transition = null, WorkflowInterface $workflow = null)
3432
{
3533
$this->subject = $subject;
3634
$this->marking = $marking;
3735
$this->transition = $transition;
3836
$this->workflow = $workflow;
39-
$this->context = $context;
4037
}
4138

4239
public function getMarking(): Marking
@@ -68,9 +65,4 @@ public function getMetadata(string $key, string|Transition|null $subject): mixed
6865
{
6966
return $this->workflow->getMetadataStore()->getMetadata($key, $subject);
7067
}
71-
72-
public function getContext(): array
73-
{
74-
return $this->context;
75-
}
7668
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class GuardEvent extends Event
2525
{
2626
private TransitionBlockerList $transitionBlockerList;
2727

28-
public function __construct(object $subject, Marking $marking, Transition $transition, WorkflowInterface $workflow = null)
28+
public function __construct(object $subject, Marking $marking, Transition $transition, ?WorkflowInterface $workflow = null)
2929
{
3030
parent::__construct($subject, $marking, $transition, $workflow);
3131

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Workflow\Event;
13+
14+
/**
15+
* @author Fabien Potencier <fabien@symfony.com>
16+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
17+
* @author Hugo Hamon <hugohamon@neuf.fr>
18+
*
19+
* @internal
20+
*/
21+
trait HasContextTrait
22+
{
23+
private array $context = [];
24+
25+
public function getContext(): array
26+
{
27+
return $this->context;
28+
}
29+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111

1212
namespace Symfony\Component\Workflow\Event;
1313

14+
use Symfony\Component\Workflow\Marking;
15+
use Symfony\Component\Workflow\Transition;
16+
use Symfony\Component\Workflow\WorkflowInterface;
17+
1418
final class LeaveEvent extends Event
1519
{
20+
use HasContextTrait;
21+
22+
public function __construct(object $subject, Marking $marking, ?Transition $transition = null, ?WorkflowInterface $workflow = null, array $context = [])
23+
{
24+
parent::__construct($subject, $marking, $transition, $workflow);
25+
26+
$this->context = $context;
27+
}
1628
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy