From 46b94ce451d08c36b9378bb140fc2b294747e21c Mon Sep 17 00:00:00 2001 From: Alessandro Chitolina Date: Sun, 16 Jun 2019 12:30:12 +0200 Subject: [PATCH] use psr event dispatcher --- composer.json | 5 +---- lib/Event/ClassMetadataLoadedEvent.php | 25 +++++++++++++++++++++++-- lib/Factory/AbstractMetadataFactory.php | 2 +- tests/Factory/MetadataFactoryTest.php | 2 +- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 1a4968b..3bdf238 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,10 @@ "doctrine/cache": "^1.4", "mikey179/vfsstream": "^1.6", "phpunit/phpunit": "^8.0", + "psr/event-dispatcher": "^1.0", "symfony/cache": "^4.3", - "symfony/event-dispatcher": "^4.3", "symfony/finder": "^4.3" }, - "conflict": { - "symfony/event-dispatcher": "<4.3" - }, "suggest": { "symfony/cache": "cache metadata", "symfony/event-dispatcher": "dispatch metadata load event", diff --git a/lib/Event/ClassMetadataLoadedEvent.php b/lib/Event/ClassMetadataLoadedEvent.php index 583484f..01b5133 100644 --- a/lib/Event/ClassMetadataLoadedEvent.php +++ b/lib/Event/ClassMetadataLoadedEvent.php @@ -3,10 +3,15 @@ namespace Kcs\Metadata\Event; use Kcs\Metadata\ClassMetadataInterface; -use Symfony\Contracts\EventDispatcher\Event; +use Psr\EventDispatcher\StoppableEventInterface; -class ClassMetadataLoadedEvent extends Event +class ClassMetadataLoadedEvent implements StoppableEventInterface { + /** + * @var bool + */ + private $propagationStopped = false; + /** * @var ClassMetadataInterface */ @@ -24,4 +29,20 @@ public function getMetadata(): ClassMetadataInterface { return $this->metadata; } + + /** + * {@inheritdoc} + */ + public function isPropagationStopped(): bool + { + return $this->propagationStopped; + } + + /** + * Stops the propagation of the event to further event listeners. + */ + public function stopPropagation(): void + { + $this->propagationStopped = true; + } } diff --git a/lib/Factory/AbstractMetadataFactory.php b/lib/Factory/AbstractMetadataFactory.php index 0a7559b..e01d308 100644 --- a/lib/Factory/AbstractMetadataFactory.php +++ b/lib/Factory/AbstractMetadataFactory.php @@ -8,7 +8,7 @@ use Kcs\Metadata\Exception\InvalidMetadataException; use Kcs\Metadata\Loader\LoaderInterface; use Psr\Cache\CacheItemPoolInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Psr\EventDispatcher\EventDispatcherInterface; abstract class AbstractMetadataFactory implements MetadataFactoryInterface { diff --git a/tests/Factory/MetadataFactoryTest.php b/tests/Factory/MetadataFactoryTest.php index 0f41c82..112964e 100644 --- a/tests/Factory/MetadataFactoryTest.php +++ b/tests/Factory/MetadataFactoryTest.php @@ -12,8 +12,8 @@ use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use Psr\Cache\CacheItemPoolInterface; +use Psr\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Cache\Adapter\ArrayAdapter; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Contracts\Cache\ItemInterface; class MockedClassMetadataFactory extends MetadataFactory