Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/Symfony/Component/Workflow/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Event extends BaseEvent
private $transition;
private $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, array $context = [])
Copy link
Member

@derrabus derrabus Dec 15, 2021

Choose a reason for hiding this comment

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

I understand that it was quite unfortunate that we forgot to remove the nullability of the argument after having deprecated passing null. However, this change is problematic:

  • Right now, it is possible to create the object without passing a workflow or setting it to null. You would break that functionality. Then again, actually setting the workflow to null would break getWorkflow(), getWorkflowName() and getMetadata().
  • This change will trigger a warning on PHP 8 because $workflow is mandatory now although it follows an optional parameter $transition.
  • The parameter $transition is effectively mandatory as well now which is a BC break.

Copy link
Member

Choose a reason for hiding this comment

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

Oops, I merged too fast, now reverted. Please submit again @lyrixx

Copy link
Member Author

Choose a reason for hiding this comment

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

Oups, good point !
So we need another round of deprecation ? we need to re-swap all arguments ? 😨

Copy link
Member

Choose a reason for hiding this comment

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

Looks like it. 😢

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe just turning Transition into a mandatory nullable argument rather than swapping.

anyway, I don't expect this constructor to be used a lot in third-party code. This code is expected to listen to events, not to trigger them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or maybe just turning Transition into a mandatory nullable argument rather than swapping.

Not possible, some events are not directly related to transition

Copy link
Member

Choose a reason for hiding this comment

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

Not possible, some events are not directly related to transition

Those events would eplicity pass null as transition then.

anyway, I don't expect this constructor to be used a lot in third-party code. This code is expected to listen to events, not to trigger them.

Me neither. This would mostly affect third party code that extends the workflow component with own logic. But since neither the Event class nor its constructor is flagged as @internal, calling the constructor in third-party code is valid.

Copy link
Member

Choose a reason for hiding this comment

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

but for that code, marking the argument as required or swapping arguments is a BC break in both cases

{
$this->subject = $subject;
$this->marking = $marking;
Expand Down