Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ProfilerListener.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 5.30 KiB


 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\HttpKernel\HttpKernelInterface;
 015  use Symfony\Component\HttpKernel\Event\GetResponseEvent;
 016  use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
 017  use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
 018  use Symfony\Component\HttpKernel\KernelEvents;
 019  use Symfony\Component\HttpKernel\Profiler\Profile;
 020  use Symfony\Component\HttpKernel\Profiler\Profiler;
 021  use Symfony\Component\HttpFoundation\RequestMatcherInterface;
 022  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 023   
 024  /**
 025   * ProfilerListener collects data for the current request by listening to the onKernelResponse event.
 026   *
 027   * @author Fabien Potencier <fabien@symfony.com>
 028   */
 029  class ProfilerListener implements EventSubscriberInterface
 030  {
 031      protected $profiler;
 032      protected $matcher;
 033      protected $onlyException;
 034      protected $onlyMasterRequests;
 035      protected $exception;
 036      protected $children;
 037      protected $requests;
 038      protected $profiles;
 039   
 040      /**
 041       * Constructor.
 042       *
 043       * @param Profiler                $profiler           A Profiler instance
 044       * @param RequestMatcherInterface $matcher            A RequestMatcher instance
 045       * @param bool                    $onlyException      true if the profiler only collects data when an exception occurs, false otherwise
 046       * @param bool                    $onlyMasterRequests true if the profiler only collects data when the request is a master request, false otherwise
 047       */
 048      public function __construct(Profiler $profiler, RequestMatcherInterface $matcher = null, $onlyException = false, $onlyMasterRequests = false)
 049      {
 050          $this->profiler = $profiler;
 051          $this->matcher = $matcher;
 052          $this->onlyException = (bool) $onlyException;
 053          $this->onlyMasterRequests = (bool) $onlyMasterRequests;
 054          $this->children = new \SplObjectStorage();
 055          $this->profiles = array();
 056      }
 057   
 058      /**
 059       * Handles the onKernelException event.
 060       *
 061       * @param GetResponseForExceptionEvent $event A GetResponseForExceptionEvent instance
 062       */
 063      public function onKernelException(GetResponseForExceptionEvent $event)
 064      {
 065          if ($this->onlyMasterRequests && HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
 066              return;
 067          }
 068   
 069          $this->exception = $event->getException();
 070      }
 071   
 072      public function onKernelRequest(GetResponseEvent $event)
 073      {
 074          $this->requests[] = $event->getRequest();
 075      }
 076   
 077      /**
 078       * Handles the onKernelResponse event.
 079       *
 080       * @param FilterResponseEvent $event A FilterResponseEvent instance
 081       */
 082      public function onKernelResponse(FilterResponseEvent $event)
 083      {
 084          $master = HttpKernelInterface::MASTER_REQUEST === $event->getRequestType();
 085          if ($this->onlyMasterRequests && !$master) {
 086              return;
 087          }
 088   
 089          if ($this->onlyException && null === $this->exception) {
 090              return;
 091          }
 092   
 093          $request = $event->getRequest();
 094          $exception = $this->exception;
 095          $this->exception = null;
 096   
 097          if (null !== $this->matcher && !$this->matcher->matches($request)) {
 098              return;
 099          }
 100   
 101          if (!$profile = $this->profiler->collect($request, $event->getResponse(), $exception)) {
 102              return;
 103          }
 104   
 105          $this->profiles[] = $profile;
 106   
 107          if (null !== $exception) {
 108              foreach ($this->profiles as $profile) {
 109                  $this->profiler->saveProfile($profile);
 110              }
 111   
 112              return;
 113          }
 114   
 115          // keep the profile as the child of its parent
 116          if (!$master) {
 117              array_pop($this->requests);
 118   
 119              $parent = end($this->requests);
 120   
 121              // when simulating requests, we might not have the parent
 122              if ($parent) {
 123                  $profiles = isset($this->children[$parent]) ? $this->children[$parent] : array();
 124                  $profiles[] = $profile;
 125                  $this->children[$parent] = $profiles;
 126              }
 127          }
 128   
 129          if (isset($this->children[$request])) {
 130              foreach ($this->children[$request] as $child) {
 131                  $profile->addChild($child);
 132              }
 133              $this->children[$request] = array();
 134          }
 135   
 136          if ($master) {
 137              $this->saveProfiles($profile);
 138   
 139              $this->children = new \SplObjectStorage();
 140          }
 141      }
 142   
 143      public static function getSubscribedEvents()
 144      {
 145          return array(
 146              // kernel.request must be registered as early as possible to not break
 147              // when an exception is thrown in any other kernel.request listener
 148              KernelEvents::REQUEST => array('onKernelRequest', 1024),
 149              KernelEvents::RESPONSE => array('onKernelResponse', -100),
 150              KernelEvents::EXCEPTION => 'onKernelException',
 151          );
 152      }
 153   
 154      /**
 155       * Saves the profile hierarchy.
 156       *
 157       * @param Profile $profile The root profile
 158       */
 159      private function saveProfiles(Profile $profile)
 160      {
 161          $this->profiler->saveProfile($profile);
 162          foreach ($profile->getChildren() as $profile) {
 163              $this->saveProfiles($profile);
 164          }
 165      }
 166  }
 167