forked from phpro/grumphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore container-aware event dispatcher
for supported Symfony versions. The container aware variant has been deprecated (3.4) and removed (4.0), but is still required to keep the RegisterListenersPass happy (2.8).
- Loading branch information
1 parent
fd171df
commit ef22792
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace spec\GrumPHP\Event; | ||
|
||
use PhpSpec\Exception\Example\SkippingException; | ||
use PhpSpec\ObjectBehavior; | ||
use GrumPHP\Event\EventDispatcherFactory; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher; | ||
use Symfony\Component\EventDispatcher\EventDispatcher; | ||
|
||
class EventDispatcherFactorySpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(EventDispatcherFactory::class); | ||
} | ||
|
||
function it_creates_an_event_dispatcher( | ||
ContainerInterface $container | ||
) { | ||
$eventDispatcher = self::create($container); | ||
$eventDispatcher->shouldBeAnInstanceOf(EventDispatcher::class); | ||
} | ||
|
||
function it_creates_a_container_aware_event_dispatcher_instead_when_available( | ||
ContainerInterface $container | ||
) { | ||
if (!class_exists(ContainerAwareEventDispatcher::class)) { | ||
throw new SkippingException('A container-aware implementation of the event dispatcher is no longer available.'); | ||
} | ||
|
||
$eventDispatcher = self::create($container); | ||
$eventDispatcher->shouldBeAnInstanceOf(ContainerAwareEventDispatcher::class); | ||
$eventDispatcher->getContainer()->shouldReturn($container); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace GrumPHP\Event; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher; | ||
use Symfony\Component\EventDispatcher\EventDispatcher; | ||
|
||
class EventDispatcherFactory | ||
{ | ||
/** | ||
* @param ContainerInterface $container | ||
* | ||
* @return EventDispatcherInterface | ||
*/ | ||
public static function create(ContainerInterface $container) | ||
{ | ||
if (class_exists(ContainerAwareEventDispatcher::class)) { | ||
return new ContainerAwareEventDispatcher($container); | ||
} | ||
|
||
return new EventDispatcher(); | ||
} | ||
} |