annotate vendor/symfony/http-kernel/DataCollector/EventDataCollector.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\HttpKernel\DataCollector;
Chris@0 13
Chris@17 14 use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface;
Chris@17 15 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Chris@0 16 use Symfony\Component\HttpFoundation\Request;
Chris@0 17 use Symfony\Component\HttpFoundation\Response;
Chris@0 18
Chris@0 19 /**
Chris@0 20 * EventDataCollector.
Chris@0 21 *
Chris@0 22 * @author Fabien Potencier <fabien@symfony.com>
Chris@0 23 */
Chris@0 24 class EventDataCollector extends DataCollector implements LateDataCollectorInterface
Chris@0 25 {
Chris@0 26 protected $dispatcher;
Chris@0 27
Chris@0 28 public function __construct(EventDispatcherInterface $dispatcher = null)
Chris@0 29 {
Chris@14 30 if ($dispatcher instanceof TraceableEventDispatcherInterface && !method_exists($dispatcher, 'reset')) {
Chris@14 31 @trigger_error(sprintf('Implementing "%s" without the "reset()" method is deprecated since Symfony 3.4 and will be unsupported in 4.0 for class "%s".', TraceableEventDispatcherInterface::class, \get_class($dispatcher)), E_USER_DEPRECATED);
Chris@14 32 }
Chris@0 33 $this->dispatcher = $dispatcher;
Chris@0 34 }
Chris@0 35
Chris@0 36 /**
Chris@0 37 * {@inheritdoc}
Chris@0 38 */
Chris@0 39 public function collect(Request $request, Response $response, \Exception $exception = null)
Chris@0 40 {
Chris@17 41 $this->data = [
Chris@17 42 'called_listeners' => [],
Chris@17 43 'not_called_listeners' => [],
Chris@17 44 ];
Chris@0 45 }
Chris@0 46
Chris@14 47 public function reset()
Chris@14 48 {
Chris@17 49 $this->data = [];
Chris@14 50
Chris@14 51 if ($this->dispatcher instanceof TraceableEventDispatcherInterface) {
Chris@14 52 if (!method_exists($this->dispatcher, 'reset')) {
Chris@14 53 return; // @deprecated
Chris@14 54 }
Chris@14 55
Chris@14 56 $this->dispatcher->reset();
Chris@14 57 }
Chris@14 58 }
Chris@14 59
Chris@0 60 public function lateCollect()
Chris@0 61 {
Chris@0 62 if ($this->dispatcher instanceof TraceableEventDispatcherInterface) {
Chris@0 63 $this->setCalledListeners($this->dispatcher->getCalledListeners());
Chris@0 64 $this->setNotCalledListeners($this->dispatcher->getNotCalledListeners());
Chris@0 65 }
Chris@14 66 $this->data = $this->cloneVar($this->data);
Chris@0 67 }
Chris@0 68
Chris@0 69 /**
Chris@0 70 * Sets the called listeners.
Chris@0 71 *
Chris@0 72 * @param array $listeners An array of called listeners
Chris@0 73 *
Chris@0 74 * @see TraceableEventDispatcherInterface
Chris@0 75 */
Chris@0 76 public function setCalledListeners(array $listeners)
Chris@0 77 {
Chris@0 78 $this->data['called_listeners'] = $listeners;
Chris@0 79 }
Chris@0 80
Chris@0 81 /**
Chris@0 82 * Gets the called listeners.
Chris@0 83 *
Chris@0 84 * @return array An array of called listeners
Chris@0 85 *
Chris@0 86 * @see TraceableEventDispatcherInterface
Chris@0 87 */
Chris@0 88 public function getCalledListeners()
Chris@0 89 {
Chris@0 90 return $this->data['called_listeners'];
Chris@0 91 }
Chris@0 92
Chris@0 93 /**
Chris@0 94 * Sets the not called listeners.
Chris@0 95 *
Chris@0 96 * @param array $listeners An array of not called listeners
Chris@0 97 *
Chris@0 98 * @see TraceableEventDispatcherInterface
Chris@0 99 */
Chris@0 100 public function setNotCalledListeners(array $listeners)
Chris@0 101 {
Chris@0 102 $this->data['not_called_listeners'] = $listeners;
Chris@0 103 }
Chris@0 104
Chris@0 105 /**
Chris@0 106 * Gets the not called listeners.
Chris@0 107 *
Chris@0 108 * @return array An array of not called listeners
Chris@0 109 *
Chris@0 110 * @see TraceableEventDispatcherInterface
Chris@0 111 */
Chris@0 112 public function getNotCalledListeners()
Chris@0 113 {
Chris@0 114 return $this->data['not_called_listeners'];
Chris@0 115 }
Chris@0 116
Chris@0 117 /**
Chris@0 118 * {@inheritdoc}
Chris@0 119 */
Chris@0 120 public function getName()
Chris@0 121 {
Chris@0 122 return 'events';
Chris@0 123 }
Chris@0 124 }