Skip to content

Commit

Permalink
Merge branch '2.4'
Browse files Browse the repository at this point in the history
* 2.4:
  added missing @deprecated tag
  Fixed recursion level incrementing in FlattenException::flattenArgs().
  [HttpKernel] fixed wrong reference in TraceableEventDispatcher

Conflicts:
	src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php
  • Loading branch information
fabpot committed Feb 4, 2014
2 parents bea1537 + aca1686 commit 22970e0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
2 changes: 2 additions & 0 deletions src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* Twig extension for Symfony actions helper
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated Deprecated in 2.2, to be removed in 3.0.
*/
class ActionsExtension extends \Twig_Extension
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Debug/Exception/FlattenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private function flattenArgs($args, $level = 0)
if ($level > 10) {
$result[$key] = array('array', '*DEEP NESTED ARRAY*');
} else {
$result[$key] = array('array', $this->flattenArgs($value, ++$level));
$result[$key] = array('array', $this->flattenArgs($value, $level + 1));
}
} elseif (null === $value) {
$result[$key] = array('null', null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
private $dispatcher;
private $wrappedListeners = array();
private $firstCalledEvent = array();
private $id;
private $lastEventId = 0;

/**
Expand Down Expand Up @@ -106,17 +105,17 @@ public function dispatch($eventName, Event $event = null)
$event = new Event();
}

$this->id = $eventId = ++$this->lastEventId;
$eventId = ++$this->lastEventId;

// Wrap all listeners before they are called
$this->wrappedListeners[$this->id] = new \SplObjectStorage();
$this->wrappedListeners[$eventId] = new \SplObjectStorage();

$listeners = $this->dispatcher->getListeners($eventName);

foreach ($listeners as $listener) {
$this->dispatcher->removeListener($eventName, $listener);
$wrapped = $this->wrapListener($eventName, $listener);
$this->wrappedListeners[$this->id][$wrapped] = $listener;
$wrapped = $this->wrapListener($eventName, $eventId, $listener);
$this->wrappedListeners[$eventId][$wrapped] = $listener;
$this->dispatcher->addListener($eventName, $wrapped);
}

Expand All @@ -132,9 +131,6 @@ public function dispatch($eventName, Event $event = null)

$this->dispatcher->dispatch($eventName, $event);

// reset the id as another event might have been dispatched during the dispatching of this event
$this->id = $eventId;

unset($this->firstCalledEvent[$eventName]);

if ($e->isStarted()) {
Expand All @@ -144,12 +140,12 @@ public function dispatch($eventName, Event $event = null)
$this->postDispatch($eventName, $event);

// Unwrap all listeners after they are called
foreach ($this->wrappedListeners[$this->id] as $wrapped) {
foreach ($this->wrappedListeners[$eventId] as $wrapped) {
$this->dispatcher->removeListener($eventName, $wrapped);
$this->dispatcher->addListener($eventName, $this->wrappedListeners[$this->id][$wrapped]);
$this->dispatcher->addListener($eventName, $this->wrappedListeners[$eventId][$wrapped]);
}

unset($this->wrappedListeners[$this->id]);
unset($this->wrappedListeners[$eventId]);

return $event;
}
Expand All @@ -171,7 +167,7 @@ public function getNotCalledListeners()

foreach ($this->getListeners() as $name => $listeners) {
foreach ($listeners as $listener) {
$info = $this->getListenerInfo($listener, $name);
$info = $this->getListenerInfo($listener, $name, null);
if (!isset($this->called[$name.'.'.$info['pretty']])) {
$notCalled[$name.'.'.$info['pretty']] = $info;
}
Expand Down Expand Up @@ -201,24 +197,24 @@ public function __call($method, $arguments)
* Whenever Symfony will require PHP 5.4, this could be changed
* to a proper private method.
*/
public function logSkippedListeners($eventName, Event $event, $listener)
public function logSkippedListeners($eventName, $eventId, Event $event, $listener)
{
if (null === $this->logger) {
return;
}

$info = $this->getListenerInfo($listener, $eventName);
$info = $this->getListenerInfo($listener, $eventName, $eventId);

$this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s".', $info['pretty'], $eventName));

$skippedListeners = $this->getListeners($eventName);
$skipped = false;

foreach ($skippedListeners as $skippedListener) {
$skippedListener = $this->unwrapListener($skippedListener);
$skippedListener = $this->unwrapListener($skippedListener, $eventId);

if ($skipped) {
$info = $this->getListenerInfo($skippedListener, $eventName);
$info = $this->getListenerInfo($skippedListener, $eventName, $eventId);
$this->logger->debug(sprintf('Listener "%s" was not called for event "%s".', $info['pretty'], $eventName));
}

Expand All @@ -235,7 +231,7 @@ public function logSkippedListeners($eventName, Event $event, $listener)
* Whenever Symfony will require PHP 5.4, this could be changed
* to a proper private method.
*/
public function preListenerCall($eventName, $listener)
public function preListenerCall($eventName, $eventId, $listener)
{
// is it the first called listener?
if (isset($this->firstCalledEvent[$eventName])) {
Expand All @@ -244,7 +240,7 @@ public function preListenerCall($eventName, $listener)
unset($this->firstCalledEvent[$eventName]);
}

$info = $this->getListenerInfo($listener, $eventName);
$info = $this->getListenerInfo($listener, $eventName, $eventId);

if (null !== $this->logger) {
$this->logger->debug(sprintf('Notified event "%s" to listener "%s".', $eventName, $info['pretty']));
Expand All @@ -263,9 +259,9 @@ public function preListenerCall($eventName, $listener)
*
* @return array Information about the listener
*/
private function getListenerInfo($listener, $eventName)
private function getListenerInfo($listener, $eventName, $eventId)
{
$listener = $this->unwrapListener($listener);
$listener = $this->unwrapListener($listener, $eventId);

$info = array(
'event' => $eventName,
Expand Down Expand Up @@ -337,12 +333,12 @@ protected function postDispatch($eventName, Event $event)
{
}

private function wrapListener($eventName, $listener)
private function wrapListener($eventName, $eventId, $listener)
{
$self = $this;

return function (Event $event) use ($self, $eventName, $listener) {
$e = $self->preListenerCall($eventName, $listener);
return function (Event $event) use ($self, $eventName, $eventId, $listener) {
$e = $self->preListenerCall($eventName, $eventId, $listener);

call_user_func($listener, $event, $eventName, $self);

Expand All @@ -351,16 +347,24 @@ private function wrapListener($eventName, $listener)
}

if ($event->isPropagationStopped()) {
$self->logSkippedListeners($eventName, $event, $listener);
$self->logSkippedListeners($eventName, $eventId, $event, $listener);
}
};
}

private function unwrapListener($listener)
private function unwrapListener($listener, $eventId)
{
// get the original listener
if (is_object($listener) && isset($this->wrappedListeners[$this->id][$listener])) {
return $this->wrappedListeners[$this->id][$listener];
if (is_object($listener)) {
if (null === $eventId) {
foreach (array_keys($this->wrappedListeners) as $eventId) {
if (isset($this->wrappedListeners[$eventId][$listener])) {
return $this->wrappedListeners[$eventId][$listener];
}
}
} elseif (isset($this->wrappedListeners[$eventId][$listener])) {
return $this->wrappedListeners[$eventId][$listener];
}
}

return $listener;
Expand Down

0 comments on commit 22970e0

Please sign in to comment.