Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ProfilerListener.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\HttpKernel\EventListener;
013
014 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
015 use Symfony\Component\HttpFoundation\RequestMatcherInterface;
016 use Symfony\Component\HttpFoundation\RequestStack;
017 use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
018 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
019 use Symfony\Component\HttpKernel\Event\PostResponseEvent;
020 use Symfony\Component\HttpKernel\KernelEvents;
021 use Symfony\Component\HttpKernel\Profiler\Profiler;
022
023 /**
024 * ProfilerListener collects data for the current request by listening to the kernel events.
025 *
026 * @author Fabien Potencier <fabien@symfony.com>
027 */
028 class ProfilerListener implements EventSubscriberInterface
029 {
030 protected $profiler;
031 protected $matcher;
032 protected $onlyException;
033 protected $onlyMasterRequests;
034 protected $exception;
035 protected $profiles;
036 protected $requestStack;
037 protected $parents;
038
039 /**
040 * @param Profiler $profiler A Profiler instance
041 * @param RequestStack $requestStack A RequestStack instance
042 * @param RequestMatcherInterface|null $matcher A RequestMatcher instance
043 * @param bool $onlyException True if the profiler only collects data when an exception occurs, false otherwise
044 * @param bool $onlyMasterRequests True if the profiler only collects data when the request is a master request, false otherwise
045 */
046 public function __construct(Profiler $profiler, RequestStack $requestStack, RequestMatcherInterface $matcher = null, $onlyException = false, $onlyMasterRequests = false)
047 {
048 $this->profiler = $profiler;
049 $this->matcher = $matcher;
050 $this->onlyException = (bool) $onlyException;
051 $this->onlyMasterRequests = (bool) $onlyMasterRequests;
052 $this->profiles = new \SplObjectStorage();
053 $this->parents = new \SplObjectStorage();
054 $this->requestStack = $requestStack;
055 }
056
057 /**
058 * Handles the onKernelException event.
059 */
060 public function onKernelException(GetResponseForExceptionEvent $event)
061 {
062 if ($this->onlyMasterRequests && !$event->isMasterRequest()) {
063 return;
064 }
065
066 $this->exception = $event->getException();
067 }
068
069 /**
070 * Handles the onKernelResponse event.
071 */
072 public function onKernelResponse(FilterResponseEvent $event)
073 {
074 $master = $event->isMasterRequest();
075 if ($this->onlyMasterRequests && !$master) {
076 return;
077 }
078
079 if ($this->onlyException && null === $this->exception) {
080 return;
081 }
082
083 $request = $event->getRequest();
084 $exception = $this->exception;
085 $this->exception = null;
086
087 if (null !== $this->matcher && !$this->matcher->matches($request)) {
088 return;
089 }
090
091 if (!$profile = $this->profiler->collect($request, $event->getResponse(), $exception)) {
092 return;
093 }
094
095 $this->profiles[$request] = $profile;
096
097 $this->parents[$request] = $this->requestStack->getParentRequest();
098 }
099
100 public function onKernelTerminate(PostResponseEvent $event)
101 {
102 // attach children to parents
103 foreach ($this->profiles as $request) {
104 if (null !== $parentRequest = $this->parents[$request]) {
105 if (isset($this->profiles[$parentRequest])) {
106 $this->profiles[$parentRequest]->addChild($this->profiles[$request]);
107 }
108 }
109 }
110
111 // save profiles
112 foreach ($this->profiles as $request) {
113 $this->profiler->saveProfile($this->profiles[$request]);
114 }
115
116 $this->profiles = new \SplObjectStorage();
117 $this->parents = new \SplObjectStorage();
118 }
119
120 public static function getSubscribedEvents()
121 {
122 return [
123 KernelEvents::RESPONSE => ['onKernelResponse', -100],
124 KernelEvents::EXCEPTION => 'onKernelException',
125 KernelEvents::TERMINATE => ['onKernelTerminate', -1024],
126 ];
127 }
128 }
129