8000 [EventDispatcher] Add Drupal EventDispatcher by znerol · Pull Request #12521 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[EventDispatcher] Add Drupal EventDispatcher #12521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix codestyle as suggested by @stof
  • Loading branch information
znerol committed Jan 18, 2015
commit d0f986df87bf77550cb0cd47696e2ab1e61bc1c2
42 changes: 24 additions & 18 deletions src/Symfony/Component/EventDispatcher/CompiledEventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CompiledEventDispatcher implements EventDispatcherInterface
/**
* The service container.
*
* @var \Symfony\Component\DependencyInjection\IntrospectableContainerInterface
* @var IntrospectableContainerInterface
*/
private $container;

Expand Down Expand Up @@ -72,7 +72,7 @@ class CompiledEventDispatcher implements EventDispatcherInterface
/**
* Constructs a container aware event dispatcher.
*
* @param \Symfony\Component\EventDispatcher\IntrospectableContainerInterface $container
* @param IntrospectableContainerInterface $container
* The service container.
* @param array $listeners
* A nested array of listener definitions keyed by event name and priority.
Expand All @@ -94,7 +94,7 @@ public function __construct(IntrospectableContainerInterface $container, array $
*/
public function dispatch($eventName, Event $event = null)
{
if ($event === NULL) {
if (null === $event) {
$event = new Event();
}

Expand All @@ -110,7 +110,7 @@ public function dispatch($eventName, Event $event = null)

// Invoke listeners and resolve callables if necessary.
foreach ($this->listeners[$eventName] as &$definitions) {
foreach ($definitions as $key => &$definition) {
foreach ($definitions as &$definition) {
if (!isset($definition['callable'])) {
$definition['callable'] = array($this->container->get($definition['service'][0]), $definition['service'][1]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of ['service'][0] and ['service'][1], I would prefer using 2 keys service and method. Otherwise, using service as key is wrong, because it does not represent a service

}
Expand All @@ -133,30 +133,36 @@ public function getListeners($eventName = null)
{
$result = array();

if ($eventName === NULL) {
if (null === $eventName) {
// If event name was omitted, collect all listeners of all events.
foreach (array_keys($this->listeners) as $eventName) {
$listeners = $this->getListeners($eventName);
if (!empty($listeners)) {
$result[$eventName] = $listeners;
}
}
} elseif (isset($this->listeners[$eventName])) {
// Sort listeners if necessary.
if (isset($this->unsorted[$eventName])) {
krsort($this->listeners[$eventName]);
unset($this->unsorted[$eventName]);
}

// Collect listeners and resolve callables if necessary.
foreach ($this->listeners[$eventName] as &$definitions) {
foreach ($definitions as $key => &$definition) {
if (!isset($definition['callable'])) {
$definition['callable'] = array($this->container->get($definition['service'][0]), $definition['service'][1]);
}
return $result;
}

$result[] = $definition['callable'];
if (!isset($this->listeners[$eventName])) {
return $result;
}

// Sort listeners if necessary.
if (isset($this->unsorted[$eventName])) {
krsort($this->listeners[$eventName]);
unset($this->unsorted[$eventName]);
}

// Collect listeners and resolve callables if necessary.
foreach ($this->listeners[$eventName] as &$definitions) {
foreach ($definitions as &$definition) {
if (!isset($definition['callable'])) {
$definition['callable'] = array($this->container->get($definition['service'][0]), $definition['service'][1]);
}

$result[] = $definition['callable'];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\EventDispatcher\DependencyInjection\CompiledRegisterListenersPass;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class CompiledRegisterListenersPassTest extends \PHPUnit_Framework_TestCase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we don't use @coversDefaultClass and @Covers ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use those annotations. You can find some @covers ones but those were added a long time ago.

{
Expand Down Expand Up @@ -140,7 +141,7 @@ public function testAbstractEventListener()
}
}

class CompiledSubscriberService implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
class CompiledSubscriberService implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
Expand Down
0