Closed
Description
Symfony version(s) affected: 5.0.0+
Description
In 5.0.0 the signature of the getMetadata
method was changed in one place to be non-nullable and require an object. This breaks backwards-compatibility without going through a deprecation cycle.
The underlying method signature hasn't changed and continues to accept - and work with - a null value.
How to reproduce
<?php
namespace App\Event\Subscriber;
use App\Entity\Application;
use App\Entity\Setting\ApplicationStatus;
use App\Lib\ApplicationMinder;
use App\Workflow\ApplicationWorkflow;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\Event;
use Symfony\Component\Workflow\Event\GuardEvent;
/**
* This is a general class for hooking into events. It's experimental and should be refactored later on
*
* Class ApplicationWorkflowEvents
* @package App\Event\Subscriber
*/
class ApplicationWorkflowEvents implements EventSubscriberInterface
{
public function __construct()
{
}
public static function getSubscribedEvents()
{
return [
// workflow.[workflow name].guard.[transition name]
'workflow.' . ApplicationWorkflow::NAME . '.entered' => 'setApplicationStatus',
];
}
/**
* Set the Application Status dropdown (the one staff see) to a new value based on metadata
* attached to the Workflow transition.
*
* @param Event $event
*
* @throws \Doctrine\ORM\ORMException
*/
public function setApplicationStatus(Event $event)
{
// @ERROR The line below works on 4.4.4, fails on 5.0.0 when $event->getTransition() === null
if ($status = $event->getMetadata('applicationStatus', $event->getTransition())) {
// Do stuff
}
}
}
Possible Solution
Alter the method signature change in symfony/workflow@680d6f2, which changed
public function getMetadata(string $key, $subject)
to
public function getMetadata(string $key, object $subject)
and make it nullable to match all other getMetadata
method signatures.