Skip to content

Commit

Permalink
Fix FC layer for the event dispatcher under Symfony < 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean85 committed Mar 17, 2020
1 parent 3bdfc41 commit a568da0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ parameters:
message: "#^Method Tests\\\\Unit\\\\Configuration\\\\CoverageConfigurationTest\\:\\:getService\\(\\) has no return typehint specified\\.$#"
count: 1
path: tests/Unit/Configuration/CoverageConfigurationTest.php
-
message: "#^Method Tests\\\\Unit\\\\Configuration\\\\OutputFileTest\\:\\:testIsEmpty\\(\\) has parameter \\$emptyFile with no typehint specified\\.$#"
count: 1
path: tests/Unit/Configuration/OutputFileTest.php
excludes_analyse:
- tests/Stub/
- src/Lifecycle/ForwardCompatEventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Paraunit\File\Cleaner;
use Paraunit\File\TempDirectory;
use Paraunit\Filter\Filter;
use Paraunit\Lifecycle\ForwardCompatEventDispatcher;
use Paraunit\Printer\ConsoleFormatter;
use Paraunit\Printer\FailuresPrinter;
use Paraunit\Printer\FilesRecapPrinter;
Expand Down Expand Up @@ -83,9 +84,9 @@ private function configureConfiguration(ContainerBuilder $container): void
private function configureEventDispatcher(ContainerBuilder $container): void
{
$eventDispatcher = new Definition(EventDispatcher::class);
if (class_exists(LegacyEventDispatcherProxy::class)) {
if (! class_exists(LegacyEventDispatcherProxy::class)) {
$container->setDefinition(LegacyEventDispatcherProxy::class, new Definition(LegacyEventDispatcherProxy::class));
$eventDispatcher->setDecoratedService(LegacyEventDispatcherProxy::class);
$eventDispatcher->setDecoratedService(ForwardCompatEventDispatcher::class);
}

$container->setDefinition(SymfonyEventDispatcherInterface::class, $eventDispatcher);
Expand Down
31 changes: 31 additions & 0 deletions src/Lifecycle/ForwardCompatEventDispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Paraunit\Lifecycle;

use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface as SymfonyEventDispatcherInterface;

class ForwardCompatEventDispatcher implements EventDispatcherInterface
{
/** @var SymfonyEventDispatcherInterface */
private $eventDispatcher;

private function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}

public static function decorate(SymfonyEventDispatcherInterface $dispatcher): self
{
return new self($dispatcher);
}

public function dispatch(object $event): object
{
$this->eventDispatcher->dispatch(\get_class($event), $event);

return $event;
}
}

0 comments on commit a568da0

Please sign in to comment.