comparison vendor/symfony/http-kernel/DataCollector/DumpDataCollector.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents 5311817fb629
children 12f9dff5fda9
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
16 use Symfony\Component\HttpFoundation\Response; 16 use Symfony\Component\HttpFoundation\Response;
17 use Symfony\Component\Stopwatch\Stopwatch; 17 use Symfony\Component\Stopwatch\Stopwatch;
18 use Symfony\Component\VarDumper\Cloner\Data; 18 use Symfony\Component\VarDumper\Cloner\Data;
19 use Symfony\Component\VarDumper\Cloner\VarCloner; 19 use Symfony\Component\VarDumper\Cloner\VarCloner;
20 use Symfony\Component\VarDumper\Dumper\CliDumper; 20 use Symfony\Component\VarDumper\Dumper\CliDumper;
21 use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
21 use Symfony\Component\VarDumper\Dumper\HtmlDumper; 22 use Symfony\Component\VarDumper\Dumper\HtmlDumper;
22 use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
23 use Twig\Template; 23 use Twig\Template;
24 24
25 /** 25 /**
26 * @author Nicolas Grekas <p@tchwork.com> 26 * @author Nicolas Grekas <p@tchwork.com>
27 */ 27 */
47 $this->requestStack = $requestStack; 47 $this->requestStack = $requestStack;
48 $this->dumper = $dumper; 48 $this->dumper = $dumper;
49 $this->dumperIsInjected = null !== $dumper; 49 $this->dumperIsInjected = null !== $dumper;
50 50
51 // All clones share these properties by reference: 51 // All clones share these properties by reference:
52 $this->rootRefs = array( 52 $this->rootRefs = [
53 &$this->data, 53 &$this->data,
54 &$this->dataCount, 54 &$this->dataCount,
55 &$this->isCollected, 55 &$this->isCollected,
56 &$this->clonesCount, 56 &$this->clonesCount,
57 ); 57 ];
58 } 58 }
59 59
60 public function __clone() 60 public function __clone()
61 { 61 {
62 $this->clonesIndex = ++$this->clonesCount; 62 $this->clonesIndex = ++$this->clonesCount;
101 $line = $info[$trace[$i - 1]['line']]; 101 $line = $info[$trace[$i - 1]['line']];
102 $file = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getPath() : null; 102 $file = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getPath() : null;
103 103
104 if ($src) { 104 if ($src) {
105 $src = explode("\n", $src); 105 $src = explode("\n", $src);
106 $fileExcerpt = array(); 106 $fileExcerpt = [];
107 107
108 for ($i = max($line - 3, 1), $max = min($line + 3, count($src)); $i <= $max; ++$i) { 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>'; 109 $fileExcerpt[] = '<li'.($i === $line ? ' class="selected"' : '').'><code>'.$this->htmlEncode($src[$i - 1]).'</code></li>';
110 } 110 }
111 111
112 $fileExcerpt = '<ol start="'.max($line - 3, 1).'">'.implode("\n", $fileExcerpt).'</ol>'; 112 $fileExcerpt = '<ol start="'.max($line - 3, 1).'">'.implode("\n", $fileExcerpt).'</ol>';
113 } 113 }
151 || 'html' !== $request->getRequestFormat() 151 || 'html' !== $request->getRequestFormat()
152 || false === strripos($response->getContent(), '</body>') 152 || false === strripos($response->getContent(), '</body>')
153 ) { 153 ) {
154 if ($response->headers->has('Content-Type') && false !== strpos($response->headers->get('Content-Type'), 'html')) { 154 if ($response->headers->has('Content-Type') && false !== strpos($response->headers->get('Content-Type'), 'html')) {
155 $this->dumper = new HtmlDumper('php://output', $this->charset); 155 $this->dumper = new HtmlDumper('php://output', $this->charset);
156 $this->dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat)); 156 $this->dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
157 } else { 157 } else {
158 $this->dumper = new CliDumper('php://output', $this->charset); 158 $this->dumper = new CliDumper('php://output', $this->charset);
159 } 159 }
160 160
161 foreach ($this->data as $dump) { 161 foreach ($this->data as $dump) {
167 public function reset() 167 public function reset()
168 { 168 {
169 if ($this->stopwatch) { 169 if ($this->stopwatch) {
170 $this->stopwatch->reset(); 170 $this->stopwatch->reset();
171 } 171 }
172 $this->data = array(); 172 $this->data = [];
173 $this->dataCount = 0; 173 $this->dataCount = 0;
174 $this->isCollected = true; 174 $this->isCollected = true;
175 $this->clonesCount = 0; 175 $this->clonesCount = 0;
176 $this->clonesIndex = 0; 176 $this->clonesIndex = 0;
177 } 177 }
178 178
179 /**
180 * @internal
181 */
179 public function serialize() 182 public function serialize()
180 { 183 {
181 if ($this->clonesCount !== $this->clonesIndex) { 184 if ($this->clonesCount !== $this->clonesIndex) {
182 return 'a:0:{}'; 185 return 'a:0:{}';
183 } 186 }
184 187
185 $this->data[] = $this->fileLinkFormat; 188 $this->data[] = $this->fileLinkFormat;
186 $this->data[] = $this->charset; 189 $this->data[] = $this->charset;
187 $ser = serialize($this->data); 190 $ser = serialize($this->data);
188 $this->data = array(); 191 $this->data = [];
189 $this->dataCount = 0; 192 $this->dataCount = 0;
190 $this->isCollected = true; 193 $this->isCollected = true;
191 if (!$this->dumperIsInjected) { 194 if (!$this->dumperIsInjected) {
192 $this->dumper = null; 195 $this->dumper = null;
193 } 196 }
194 197
195 return $ser; 198 return $ser;
196 } 199 }
197 200
201 /**
202 * @internal
203 */
198 public function unserialize($data) 204 public function unserialize($data)
199 { 205 {
200 parent::unserialize($data); 206 $this->data = unserialize($data);
201 $charset = array_pop($this->data); 207 $charset = array_pop($this->data);
202 $fileLinkFormat = array_pop($this->data); 208 $fileLinkFormat = array_pop($this->data);
203 $this->dataCount = count($this->data); 209 $this->dataCount = \count($this->data);
204 self::__construct($this->stopwatch, $fileLinkFormat, $charset); 210 self::__construct($this->stopwatch, $fileLinkFormat, $charset);
205 } 211 }
206 212
207 public function getDumpsCount() 213 public function getDumpsCount()
208 { 214 {
213 { 219 {
214 $data = fopen('php://memory', 'r+b'); 220 $data = fopen('php://memory', 'r+b');
215 221
216 if ('html' === $format) { 222 if ('html' === $format) {
217 $dumper = new HtmlDumper($data, $this->charset); 223 $dumper = new HtmlDumper($data, $this->charset);
218 $dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat)); 224 $dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
219 } else { 225 } else {
220 throw new \InvalidArgumentException(sprintf('Invalid dump format: %s', $format)); 226 throw new \InvalidArgumentException(sprintf('Invalid dump format: %s', $format));
221 } 227 }
222 $dumps = array(); 228 $dumps = [];
223 229
224 foreach ($this->data as $dump) { 230 foreach ($this->data as $dump) {
225 $dumper->dump($dump['data']->withMaxDepth($maxDepthLimit)->withMaxItemsPerDepth($maxItemsPerDepth)); 231 $dumper->dump($dump['data']->withMaxDepth($maxDepthLimit)->withMaxItemsPerDepth($maxItemsPerDepth));
226 $dump['data'] = stream_get_contents($data, -1, 0); 232 $dump['data'] = stream_get_contents($data, -1, 0);
227 ftruncate($data, 0); 233 ftruncate($data, 0);
242 if (0 === $this->clonesCount-- && !$this->isCollected && $this->data) { 248 if (0 === $this->clonesCount-- && !$this->isCollected && $this->data) {
243 $this->clonesCount = 0; 249 $this->clonesCount = 0;
244 $this->isCollected = true; 250 $this->isCollected = true;
245 251
246 $h = headers_list(); 252 $h = headers_list();
247 $i = count($h); 253 $i = \count($h);
248 array_unshift($h, 'Content-Type: '.ini_get('default_mimetype')); 254 array_unshift($h, 'Content-Type: '.ini_get('default_mimetype'));
249 while (0 !== stripos($h[$i], 'Content-Type:')) { 255 while (0 !== stripos($h[$i], 'Content-Type:')) {
250 --$i; 256 --$i;
251 } 257 }
252 258
253 if (!\in_array(PHP_SAPI, array('cli', 'phpdbg'), true) && stripos($h[$i], 'html')) { 259 if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && stripos($h[$i], 'html')) {
254 $this->dumper = new HtmlDumper('php://output', $this->charset); 260 $this->dumper = new HtmlDumper('php://output', $this->charset);
255 $this->dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat)); 261 $this->dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
256 } else { 262 } else {
257 $this->dumper = new CliDumper('php://output', $this->charset); 263 $this->dumper = new CliDumper('php://output', $this->charset);
258 } 264 }
259 265
260 foreach ($this->data as $i => $dump) { 266 foreach ($this->data as $i => $dump) {
261 $this->data[$i] = null; 267 $this->data[$i] = null;
262 $this->doDump($dump['data'], $dump['name'], $dump['file'], $dump['line']); 268 $this->doDump($dump['data'], $dump['name'], $dump['file'], $dump['line']);
263 } 269 }
264 270
265 $this->data = array(); 271 $this->data = [];
266 $this->dataCount = 0; 272 $this->dataCount = 0;
267 } 273 }
268 } 274 }
269 275
270 private function doDump($data, $name, $file, $line) 276 private function doDump($data, $name, $file, $line)
274 if ($this instanceof HtmlDumper) { 280 if ($this instanceof HtmlDumper) {
275 if ($file) { 281 if ($file) {
276 $s = $this->style('meta', '%s'); 282 $s = $this->style('meta', '%s');
277 $f = strip_tags($this->style('', $file)); 283 $f = strip_tags($this->style('', $file));
278 $name = strip_tags($this->style('', $name)); 284 $name = strip_tags($this->style('', $name));
279 if ($fmt && $link = is_string($fmt) ? strtr($fmt, array('%f' => $file, '%l' => $line)) : $fmt->format($file, $line)) { 285 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); 286 $name = sprintf('<a href="%s" title="%s">'.$s.'</a>', strip_tags($this->style('', $link)), $f, $name);
281 } else { 287 } else {
282 $name = sprintf('<abbr title="%s">'.$s.'</abbr>', $f, $name); 288 $name = sprintf('<abbr title="%s">'.$s.'</abbr>', $f, $name);
283 } 289 }
284 } else { 290 } else {