Skip to content

Favour composition over inheritance of symfony/external interfaces #1316

@rpkamp

Description

@rpkamp

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions