8000 Remove `GuardEvent::getContext()` method and add `HasContextTrait` trait by hhamon · Pull Request #51493 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Remove GuardEvent::getContext() method and add HasContextTrait trait #51493

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

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions UPGRADE-7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ Workflow
--------

* Require explicit argument when calling `Definition::setInitialPlaces()`
* `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.

Yaml
----
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Workflow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

* Require explicit argument when calling `Definition::setInitialPlaces()`
* `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.

6.4
---
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/Workflow/Event/AnnounceEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@

namespace Symfony\Component\Workflow\Event;

use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\WorkflowInterface;

final class AnnounceEvent extends Event
{
use HasContextTrait;

public function __construct(object $subject, Marking $marking, Transition $transition = null, WorkflowInterface $workflow = null, array $context = [])
{
parent::__construct($subject, $marking, $transition, $workflow);

$this->context = $context;
}
}
12 changes: 12 additions & 0 deletions src/Symfony/Component/Workflow/Event/CompletedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@

namespace Symfony\Component\Workflow\Event;

use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\WorkflowInterface;

final class CompletedEvent extends Event
{
use HasContextTrait;

public function __construct(object $subject, Marking $marking, Transition $transition = null, WorkflowInterface $workflow = null, array $context = [])
{
parent::__construct($subject, $marking, $transition, $workflow);

$this->context = $context;
}
}
12 changes: 12 additions & 0 deletions src/Symfony/Component/Workflow/Event/EnterEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@

namespace Symfony\Component\Workflow\Event;

use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\WorkflowInterface;

final class EnterEvent extends Event
{
use HasContextTrait;

public function __construct(object $subject, Marking $marking, Transition $transition = null, WorkflowInterface $workflow = null, array $context = [])
{
parent::__construct($subject, $marking, $transition, $workflow);

$this->context = $context;
}
}
12 changes: 12 additions & 0 deletions src/Symfony/Component/Workflow/Event/EnteredEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@

namespace Symfony\Component\Workflow\Event;

use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\WorkflowInterface;

final class EnteredEvent extends Event
{
use HasContextTrait;

public function __construct(object $subject, Marking $marking, Transition $transition = null, WorkflowInterface $workflow = null, array $context = [])
{
parent::__construct($subject, $marking, $transition, $workflow);

$this->context = $context;
}
}
10 changes: 1 addition & 9 deletions src/Symfony/Component/Workflow/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@
*/
class Event extends BaseEvent
{
protected array $context;

private object $subject;
private Marking $marking;
private ?Transition $transition;
private ?WorkflowInterface $workflow;

public function __construct(object $subject, Marking $marking, Transition $transition = null, WorkflowInterface $workflow = null, array $context = [])
public function __construct(object $subject, Marking $marking, Transition $transition = null, WorkflowInterface $workflow = null)
{
$this->subject = $subject;
$this->marking = $marking;
$this->transition = $transition;
$this->workflow = $workflow;
$this->context = $context;
}

public function getMarking(): Marking
Expand Down Expand Up @@ -68,9 +65,4 @@ public function getMetadata(string $key, string|Transition|null $subject): mixed
{
return $this->workflow->getMetadataStore()->getMetadata($key, $subject);
}

public function getContext(): array
{
return $this->context;
}
}
29 changes: 29 additions & 0 deletions src/Symfony/Component/Workflow/Event/HasContextTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Workflow\Event;

/**
* @author Fabien Potencier <fabien@symfony.com>
* @author Grégoire Pineau <lyrixx@lyrixx.info>
* @author Hugo Hamon <hugohamon@neuf.fr>
*
* @internal
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trait is marked internal as it's not supposed to be used outside of the Workflow component itself.

*/
trait HasContextTrait
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'm not sure about the naming of this trait although it's purely made for an internal use. I was also thinking of naming it HoldContextTrait. Any other better suggestions are welcome and appreciated.

{
private array $context = [];
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 made the property private instead of protected as all concrete classes using this trait are already all final. Although it may be a potential BC break, it should not as event classes are final and internal. Application code should are not supposed to extend the base abstract Event class to produce new subtypes of workflow events.


public function getContext(): array
{
return $this->context;
}
}
12 changes: 12 additions & 0 deletions src/Symfony/Component/Workflow/Event/LeaveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@

namespace Symfony\Component\Workflow\Event;

use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\WorkflowInterface;

final class LeaveEvent extends Event
{
use HasContextTrait;

public function __construct(object $subject, Marking $marking, Transition $transition = null, WorkflowInterface $workflow = null, array $context = [])
{
parent::__construct($subject, $marking, $transition, $workflow);

$this->context = $context;
}
}
13 changes: 13 additions & 0 deletions src/Symfony/Component/Workflow/Event/TransitionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@

namespace Symfony\Component\Workflow\Event;

use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\WorkflowInterface;

final class TransitionEvent extends Event
{
use HasContextTrait;

public function __construct(object $subject, Marking $marking, Transition $transition = null, WorkflowInterface $workflow = null, array $context = [])
{
parent::__construct($subject, $marking, $transition, $workflow);

$this->context = $context;
}

public function setContext(array $context): void
{
$this->context = $context;
Expand Down
0