-
-
Notifications
You must be signed in to change notification settings - Fork 612
Description
Instead of extending several Symfony classes, we should favour composition instead. For example, for the dispatcher it could be something like:
class TestworkEventDispatcher
{
private $eventDispatcher;
public function __construct()
{
$this->eventDispatcher = new Symfony\Component\Event\EventDispatcher();
}
public function addListener($eventName, $event)
{
$this->eventDispatcher->addListener($eventName, $event);
}
public function dispatch($event)
{
$this->dispatcher->dispatch($event);
}
}
This has the advantage that the Symfony Event dispatcher truly becomes an implementation detail, and can be swapped at any moment if it doesn't serve its purpose anymore. Also, it would prevent situations like we just had where a deprecation in the Symfony Dispatcher caused all classes that used the EventDispatcher to change as well.
Had there been encapsulation instead of inheritance the TestworkEventDispatcher could have done the BC layer and the rest of the code wouldn't need to be touched.
This is a BC break, since some extensions may depend on the concrete implementation of Symfony. So if we do this there should be a nice upgrade path.