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 |
DumpDataCollector.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\RequestStack;
016 use Symfony\Component\HttpFoundation\Response;
017 use Symfony\Component\Stopwatch\Stopwatch;
018 use Symfony\Component\VarDumper\Cloner\Data;
019 use Symfony\Component\VarDumper\Cloner\VarCloner;
020 use Symfony\Component\VarDumper\Dumper\CliDumper;
021 use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
022 use Symfony\Component\VarDumper\Dumper\HtmlDumper;
023 use Twig\Template;
024
025 /**
026 * @author Nicolas Grekas <p@tchwork.com>
027 */
028 class DumpDataCollector extends DataCollector implements DataDumperInterface
029 {
030 private $stopwatch;
031 private $fileLinkFormat;
032 private $dataCount = 0;
033 private $isCollected = true;
034 private $clonesCount = 0;
035 private $clonesIndex = 0;
036 private $rootRefs;
037 private $charset;
038 private $requestStack;
039 private $dumper;
040 private $dumperIsInjected;
041
042 public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, $charset = null, RequestStack $requestStack = null, DataDumperInterface $dumper = null)
043 {
044 $this->stopwatch = $stopwatch;
045 $this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
046 $this->charset = $charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8';
047 $this->requestStack = $requestStack;
048 $this->dumper = $dumper;
049 $this->dumperIsInjected = null !== $dumper;
050
051 // All clones share these properties by reference:
052 $this->rootRefs = [
053 &$this->data,
054 &$this->dataCount,
055 &$this->isCollected,
056 &$this->clonesCount,
057 ];
058 }
059
060 public function __clone()
061 {
062 $this->clonesIndex = ++$this->clonesCount;
063 }
064
065 public function dump(Data $data)
066 {
067 if ($this->stopwatch) {
068 $this->stopwatch->start('dump');
069 }
070 if ($this->isCollected && !$this->dumper) {
071 $this->isCollected = false;
072 }
073
074 $trace = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS, 7);
075
076 $file = $trace[0]['file'];
077 $line = $trace[0]['line'];
078 $name = false;
079 $fileExcerpt = false;
080
081 for ($i = 1; $i < 7; ++$i) {
082 if (isset($trace[$i]['class'], $trace[$i]['function'])
083 && 'dump' === $trace[$i]['function']
084 && 'Symfony\Component\VarDumper\VarDumper' === $trace[$i]['class']
085 ) {
086 $file = $trace[$i]['file'];
087 $line = $trace[$i]['line'];
088
089 while (++$i < 7) {
090 if (isset($trace[$i]['function'], $trace[$i]['file']) && empty($trace[$i]['class']) && 0 !== strpos($trace[$i]['function'], 'call_user_func')) {
091 $file = $trace[$i]['file'];
092 $line = $trace[$i]['line'];
093
094 break;
095 } elseif (isset($trace[$i]['object']) && $trace[$i]['object'] instanceof Template) {
096 $template = $trace[$i]['object'];
097 $name = $template->getTemplateName();
098 $src = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : false);
099 $info = $template->getDebugInfo();
100 if (isset($info[$trace[$i - 1]['line']])) {
101 $line = $info[$trace[$i - 1]['line']];
102 $file = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getPath() : null;
103
104 if ($src) {
105 $src = explode("\n", $src);
106 $fileExcerpt = [];
107
108 for ($i = max($line - 3, 1), $max = min($line + 3, \count($src)); $i <= $max; ++$i) {
109 $fileExcerpt[] = '<li'.($i === $line ? ' class="selected"' : '').'><code>'.$this->htmlEncode($src[$i - 1]).'</code></li>';
110 }
111
112 $fileExcerpt = '<ol start="'.max($line - 3, 1).'">'.implode("\n", $fileExcerpt).'</ol>';
113 }
114 }
115 break;
116 }
117 }
118 break;
119 }
120 }
121
122 if (false === $name) {
123 $name = str_replace('\\', '/', $file);
124 $name = substr($name, strrpos($name, '/') + 1);
125 }
126
127 if ($this->dumper) {
128 $this->doDump($data, $name, $file, $line);
129 }
130
131 $this->data[] = compact('data', 'name', 'file', 'line', 'fileExcerpt');
132 ++$this->dataCount;
133
134 if ($this->stopwatch) {
135 $this->stopwatch->stop('dump');
136 }
137 }
138
139 public function collect(Request $request, Response $response, \Exception $exception = null)
140 {
141 // Sub-requests and programmatic calls stay in the collected profile.
142 if ($this->dumper || ($this->requestStack && $this->requestStack->getMasterRequest() !== $request) || $request->isXmlHttpRequest() || $request->headers->has('Origin')) {
143 return;
144 }
145
146 // In all other conditions that remove the web debug toolbar, dumps are written on the output.
147 if (!$this->requestStack
148 || !$response->headers->has('X-Debug-Token')
149 || $response->isRedirection()
150 || ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
151 || 'html' !== $request->getRequestFormat()
152 || false === strripos($response->getContent(), '</body>')
153 ) {
154 if ($response->headers->has('Content-Type') && false !== strpos($response->headers->get('Content-Type'), 'html')) {
155 $this->dumper = new HtmlDumper('php://output', $this->charset);
156 $this->dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
157 } else {
158 $this->dumper = new CliDumper('php://output', $this->charset);
159 }
160
161 foreach ($this->data as $dump) {
162 $this->doDump($dump['data'], $dump['name'], $dump['file'], $dump['line']);
163 }
164 }
165 }
166
167 public function reset()
168 {
169 if ($this->stopwatch) {
170 $this->stopwatch->reset();
171 }
172 $this->data = [];
173 $this->dataCount = 0;
174 $this->isCollected = true;
175 $this->clonesCount = 0;
176 $this->clonesIndex = 0;
177 }
178
179 public function serialize()
180 {
181 if ($this->clonesCount !== $this->clonesIndex) {
182 return 'a:0:{}';
183 }
184
185 $this->data[] = $this->fileLinkFormat;
186 $this->data[] = $this->charset;
187 $ser = serialize($this->data);
188 $this->data = [];
189 $this->dataCount = 0;
190 $this->isCollected = true;
191 if (!$this->dumperIsInjected) {
192 $this->dumper = null;
193 }
194
195 return $ser;
196 }
197
198 public function unserialize($data)
199 {
200 $this->data = unserialize($data);
201 $charset = array_pop($this->data);
202 $fileLinkFormat = array_pop($this->data);
203 $this->dataCount = \count($this->data);
204 self::__construct($this->stopwatch, $fileLinkFormat, $charset);
205 }
206
207 public function getDumpsCount()
208 {
209 return $this->dataCount;
210 }
211
212 public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1)
213 {
214 $data = fopen('php://memory', 'r+b');
215
216 if ('html' === $format) {
217 $dumper = new HtmlDumper($data, $this->charset);
218 $dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
219 } else {
220 throw new \InvalidArgumentException(sprintf('Invalid dump format: "%s".', $format));
221 }
222 $dumps = [];
223
224 foreach ($this->data as $dump) {
225 $dumper->dump($dump['data']->withMaxDepth($maxDepthLimit)->withMaxItemsPerDepth($maxItemsPerDepth));
226 $dump['data'] = stream_get_contents($data, -1, 0);
227 ftruncate($data, 0);
228 rewind($data);
229 $dumps[] = $dump;
230 }
231
232 return $dumps;
233 }
234
235 public function getName()
236 {
237 return 'dump';
238 }
239
240 public function __destruct()
241 {
242 if (0 === $this->clonesCount-- && !$this->isCollected && $this->data) {
243 $this->clonesCount = 0;
244 $this->isCollected = true;
245
246 $h = headers_list();
247 $i = \count($h);
248 array_unshift($h, 'Content-Type: '.ini_get('default_mimetype'));
249 while (0 !== stripos($h[$i], 'Content-Type:')) {
250 --$i;
251 }
252
253 if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && stripos($h[$i], 'html')) {
254 $this->dumper = new HtmlDumper('php://output', $this->charset);
255 $this->dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
256 } else {
257 $this->dumper = new CliDumper('php://output', $this->charset);
258 }
259
260 foreach ($this->data as $i => $dump) {
261 $this->data[$i] = null;
262 $this->doDump($dump['data'], $dump['name'], $dump['file'], $dump['line']);
263 }
264
265 $this->data = [];
266 $this->dataCount = 0;
267 }
268 }
269
270 private function doDump($data, $name, $file, $line)
271 {
272 if ($this->dumper instanceof CliDumper) {
273 $contextDumper = function ($name, $file, $line, $fmt) {
274 if ($this instanceof HtmlDumper) {
275 if ($file) {
276 $s = $this->style('meta', '%s');
277 $f = strip_tags($this->style('', $file));
278 $name = strip_tags($this->style('', $name));
279 if ($fmt && $link = \is_string($fmt) ? strtr($fmt, ['%f' => $file, '%l' => $line]) : $fmt->format($file, $line)) {
280 $name = sprintf('<a href="%s" title="%s">'.$s.'</a>', strip_tags($this->style('', $link)), $f, $name);
281 } else {
282 $name = sprintf('<abbr title="%s">'.$s.'</abbr>', $f, $name);
283 }
284 } else {
285 $name = $this->style('meta', $name);
286 }
287 $this->line = $name.' on line '.$this->style('meta', $line).':';
288 } else {
289 $this->line = $this->style('meta', $name).' on line '.$this->style('meta', $line).':';
290 }
291 $this->dumpLine(0);
292 };
293 $contextDumper = $contextDumper->bindTo($this->dumper, $this->dumper);
294 $contextDumper($name, $file, $line, $this->fileLinkFormat);
295 } else {
296 $cloner = new VarCloner();
297 $this->dumper->dump($cloner->cloneVar($name.' on line '.$line.':'));
298 }
299 $this->dumper->dump($data);
300 }
301
302 private function htmlEncode($s)
303 {
304 $html = '';
305
306 $dumper = new HtmlDumper(function ($line) use (&$html) { $html .= $line; }, $this->charset);
307 $dumper->setDumpHeader('');
308 $dumper->setDumpBoundaries('', '');
309
310 $cloner = new VarCloner();
311 $dumper->dump($cloner->cloneVar($s));
312
313 return substr(strip_tags($html), 1, -1);
314 }
315 }
316