TrackManiaControl/libs/Symfony/Component/EventDispatcher/Debug/WrappedListener.php

72 lines
1.7 KiB
PHP
Raw Normal View History

2015-01-19 11:12:40 +01:00
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\EventDispatcher\Debug;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
class WrappedListener
{
private $listener;
private $name;
private $called;
private $stoppedPropagation;
private $stopwatch;
2015-06-19 18:51:09 +02:00
private $dispatcher;
2015-01-19 11:12:40 +01:00
2015-06-19 18:51:09 +02:00
public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
2015-01-19 11:12:40 +01:00
{
$this->listener = $listener;
$this->name = $name;
$this->stopwatch = $stopwatch;
2015-06-19 18:51:09 +02:00
$this->dispatcher = $dispatcher;
2015-01-19 11:12:40 +01:00
$this->called = false;
$this->stoppedPropagation = false;
}
public function getWrappedListener()
{
return $this->listener;
}
public function wasCalled()
{
return $this->called;
}
public function stoppedPropagation()
{
return $this->stoppedPropagation;
}
public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher)
{
$this->called = true;
$e = $this->stopwatch->start($this->name, 'event_listener');
2015-06-19 18:51:09 +02:00
call_user_func($this->listener, $event, $eventName, $this->dispatcher ?: $dispatcher);
2015-01-19 11:12:40 +01:00
if ($e->isStarted()) {
$e->stop();
}
if ($event->isPropagationStopped()) {
$this->stoppedPropagation = true;
}
}
}