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 |
TimeDataCollector.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\DataCollector;
013
014 use Symfony\Component\HttpFoundation\Request;
015 use Symfony\Component\HttpFoundation\Response;
016 use Symfony\Component\HttpKernel\KernelInterface;
017 use Symfony\Component\Stopwatch\Stopwatch;
018 use Symfony\Component\Stopwatch\StopwatchEvent;
019
020 /**
021 * @author Fabien Potencier <fabien@symfony.com>
022 */
023 class TimeDataCollector extends DataCollector implements LateDataCollectorInterface
024 {
025 protected $kernel;
026 protected $stopwatch;
027
028 public function __construct(KernelInterface $kernel = null, Stopwatch $stopwatch = null)
029 {
030 $this->kernel = $kernel;
031 $this->stopwatch = $stopwatch;
032 }
033
034 /**
035 * {@inheritdoc}
036 */
037 public function collect(Request $request, Response $response, \Exception $exception = null)
038 {
039 if (null !== $this->kernel) {
040 $startTime = $this->kernel->getStartTime();
041 } else {
042 $startTime = $request->server->get('REQUEST_TIME_FLOAT');
043 }
044
045 $this->data = [
046 'token' => $response->headers->get('X-Debug-Token'),
047 'start_time' => $startTime * 1000,
048 'events' => [],
049 'stopwatch_installed' => class_exists(Stopwatch::class, false),
050 ];
051 }
052
053 /**
054 * {@inheritdoc}
055 */
056 public function reset()
057 {
058 $this->data = [];
059
060 if (null !== $this->stopwatch) {
061 $this->stopwatch->reset();
062 }
063 }
064
065 /**
066 * {@inheritdoc}
067 */
068 public function lateCollect()
069 {
070 if (null !== $this->stopwatch && isset($this->data['token'])) {
071 $this->setEvents($this->stopwatch->getSectionEvents($this->data['token']));
072 }
073 unset($this->data['token']);
074 }
075
076 /**
077 * Sets the request events.
078 *
079 * @param StopwatchEvent[] $events The request events
080 */
081 public function setEvents(array $events)
082 {
083 foreach ($events as $event) {
084 $event->ensureStopped();
085 }
086
087 $this->data['events'] = $events;
088 }
089
090 /**
091 * Gets the request events.
092 *
093 * @return StopwatchEvent[] The request events
094 */
095 public function getEvents()
096 {
097 return $this->data['events'];
098 }
099
100 /**
101 * Gets the request elapsed time.
102 *
103 * @return float The elapsed time
104 */
105 public function getDuration()
106 {
107 if (!isset($this->data['events']['__section__'])) {
108 return 0;
109 }
110
111 $lastEvent = $this->data['events']['__section__'];
112
113 return $lastEvent->getOrigin() + $lastEvent->getDuration() - $this->getStartTime();
114 }
115
116 /**
117 * Gets the initialization time.
118 *
119 * This is the time spent until the beginning of the request handling.
120 *
121 * @return float The elapsed time
122 */
123 public function getInitTime()
124 {
125 if (!isset($this->data['events']['__section__'])) {
126 return 0;
127 }
128
129 return $this->data['events']['__section__']->getOrigin() - $this->getStartTime();
130 }
131
132 /**
133 * Gets the request time.
134 *
135 * @return float
136 */
137 public function getStartTime()
138 {
139 return $this->data['start_time'];
140 }
141
142 /**
143 * @return bool whether or not the stopwatch component is installed
144 */
145 public function isStopwatchInstalled()
146 {
147 return $this->data['stopwatch_installed'];
148 }
149
150 /**
151 * {@inheritdoc}
152 */
153 public function getName()
154 {
155 return 'time';
156 }
157 }
158