Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/http-kernel/DataCollector/RequestDataCollector.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
9 * file that was distributed with this source code. | 9 * file that was distributed with this source code. |
10 */ | 10 */ |
11 | 11 |
12 namespace Symfony\Component\HttpKernel\DataCollector; | 12 namespace Symfony\Component\HttpKernel\DataCollector; |
13 | 13 |
14 use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
14 use Symfony\Component\HttpFoundation\Cookie; | 15 use Symfony\Component\HttpFoundation\Cookie; |
15 use Symfony\Component\HttpFoundation\ParameterBag; | 16 use Symfony\Component\HttpFoundation\ParameterBag; |
16 use Symfony\Component\HttpFoundation\Request; | 17 use Symfony\Component\HttpFoundation\Request; |
17 use Symfony\Component\HttpFoundation\Response; | 18 use Symfony\Component\HttpFoundation\Response; |
19 use Symfony\Component\HttpKernel\Event\FilterControllerEvent; | |
18 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; | 20 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; |
19 use Symfony\Component\HttpKernel\KernelEvents; | 21 use Symfony\Component\HttpKernel\KernelEvents; |
20 use Symfony\Component\HttpKernel\Event\FilterControllerEvent; | |
21 use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
22 | 22 |
23 /** | 23 /** |
24 * @author Fabien Potencier <fabien@symfony.com> | 24 * @author Fabien Potencier <fabien@symfony.com> |
25 */ | 25 */ |
26 class RequestDataCollector extends DataCollector implements EventSubscriberInterface, LateDataCollectorInterface | 26 class RequestDataCollector extends DataCollector implements EventSubscriberInterface, LateDataCollectorInterface |
36 * {@inheritdoc} | 36 * {@inheritdoc} |
37 */ | 37 */ |
38 public function collect(Request $request, Response $response, \Exception $exception = null) | 38 public function collect(Request $request, Response $response, \Exception $exception = null) |
39 { | 39 { |
40 // attributes are serialized and as they can be anything, they need to be converted to strings. | 40 // attributes are serialized and as they can be anything, they need to be converted to strings. |
41 $attributes = array(); | 41 $attributes = []; |
42 $route = ''; | 42 $route = ''; |
43 foreach ($request->attributes->all() as $key => $value) { | 43 foreach ($request->attributes->all() as $key => $value) { |
44 if ('_route' === $key) { | 44 if ('_route' === $key) { |
45 $route = is_object($value) ? $value->getPath() : $value; | 45 $route = \is_object($value) ? $value->getPath() : $value; |
46 $attributes[$key] = $route; | 46 $attributes[$key] = $route; |
47 } else { | 47 } else { |
48 $attributes[$key] = $value; | 48 $attributes[$key] = $value; |
49 } | 49 } |
50 } | 50 } |
55 } catch (\LogicException $e) { | 55 } catch (\LogicException $e) { |
56 // the user already got the request content as a resource | 56 // the user already got the request content as a resource |
57 $content = false; | 57 $content = false; |
58 } | 58 } |
59 | 59 |
60 $sessionMetadata = array(); | 60 $sessionMetadata = []; |
61 $sessionAttributes = array(); | 61 $sessionAttributes = []; |
62 $session = null; | 62 $session = null; |
63 $flashes = array(); | 63 $flashes = []; |
64 if ($request->hasSession()) { | 64 if ($request->hasSession()) { |
65 $session = $request->getSession(); | 65 $session = $request->getSession(); |
66 if ($session->isStarted()) { | 66 if ($session->isStarted()) { |
67 $sessionMetadata['Created'] = date(DATE_RFC822, $session->getMetadataBag()->getCreated()); | 67 $sessionMetadata['Created'] = date(DATE_RFC822, $session->getMetadataBag()->getCreated()); |
68 $sessionMetadata['Last used'] = date(DATE_RFC822, $session->getMetadataBag()->getLastUsed()); | 68 $sessionMetadata['Last used'] = date(DATE_RFC822, $session->getMetadataBag()->getLastUsed()); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 $statusCode = $response->getStatusCode(); | 75 $statusCode = $response->getStatusCode(); |
76 | 76 |
77 $responseCookies = array(); | 77 $responseCookies = []; |
78 foreach ($response->headers->getCookies() as $cookie) { | 78 foreach ($response->headers->getCookies() as $cookie) { |
79 $responseCookies[$cookie->getName()] = $cookie; | 79 $responseCookies[$cookie->getName()] = $cookie; |
80 } | 80 } |
81 | 81 |
82 $this->data = array( | 82 $this->data = [ |
83 'method' => $request->getMethod(), | 83 'method' => $request->getMethod(), |
84 'format' => $request->getRequestFormat(), | 84 'format' => $request->getRequestFormat(), |
85 'content' => $content, | 85 'content' => $content, |
86 'content_type' => $response->headers->get('Content-Type', 'text/html'), | 86 'content_type' => $response->headers->get('Content-Type', 'text/html'), |
87 'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '', | 87 'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '', |
99 'session_attributes' => $sessionAttributes, | 99 'session_attributes' => $sessionAttributes, |
100 'flashes' => $flashes, | 100 'flashes' => $flashes, |
101 'path_info' => $request->getPathInfo(), | 101 'path_info' => $request->getPathInfo(), |
102 'controller' => 'n/a', | 102 'controller' => 'n/a', |
103 'locale' => $request->getLocale(), | 103 'locale' => $request->getLocale(), |
104 ); | 104 ]; |
105 | 105 |
106 if (isset($this->data['request_headers']['php-auth-pw'])) { | 106 if (isset($this->data['request_headers']['php-auth-pw'])) { |
107 $this->data['request_headers']['php-auth-pw'] = '******'; | 107 $this->data['request_headers']['php-auth-pw'] = '******'; |
108 } | 108 } |
109 | 109 |
114 if (isset($this->data['request_request']['_password'])) { | 114 if (isset($this->data['request_request']['_password'])) { |
115 $this->data['request_request']['_password'] = '******'; | 115 $this->data['request_request']['_password'] = '******'; |
116 } | 116 } |
117 | 117 |
118 foreach ($this->data as $key => $value) { | 118 foreach ($this->data as $key => $value) { |
119 if (!is_array($value)) { | 119 if (!\is_array($value)) { |
120 continue; | 120 continue; |
121 } | 121 } |
122 if ('request_headers' === $key || 'response_headers' === $key) { | 122 if ('request_headers' === $key || 'response_headers' === $key) { |
123 $this->data[$key] = array_map(function ($v) { return isset($v[0]) && !isset($v[1]) ? $v[0] : $v; }, $value); | 123 $this->data[$key] = array_map(function ($v) { return isset($v[0]) && !isset($v[1]) ? $v[0] : $v; }, $value); |
124 } | 124 } |
136 } | 136 } |
137 | 137 |
138 if ($response->isRedirect()) { | 138 if ($response->isRedirect()) { |
139 $response->headers->setCookie(new Cookie( | 139 $response->headers->setCookie(new Cookie( |
140 'sf_redirect', | 140 'sf_redirect', |
141 json_encode(array( | 141 json_encode([ |
142 'token' => $response->headers->get('x-debug-token'), | 142 'token' => $response->headers->get('x-debug-token'), |
143 'route' => $request->attributes->get('_route', 'n/a'), | 143 'route' => $request->attributes->get('_route', 'n/a'), |
144 'method' => $request->getMethod(), | 144 'method' => $request->getMethod(), |
145 'controller' => $this->parseController($request->attributes->get('_controller')), | 145 'controller' => $this->parseController($request->attributes->get('_controller')), |
146 'status_code' => $statusCode, | 146 'status_code' => $statusCode, |
147 'status_text' => Response::$statusTexts[(int) $statusCode], | 147 'status_text' => Response::$statusTexts[(int) $statusCode], |
148 )) | 148 ]) |
149 )); | 149 )); |
150 } | 150 } |
151 | 151 |
152 $this->data['identifier'] = $this->data['route'] ?: (is_array($this->data['controller']) ? $this->data['controller']['class'].'::'.$this->data['controller']['method'].'()' : $this->data['controller']); | 152 $this->data['identifier'] = $this->data['route'] ?: (\is_array($this->data['controller']) ? $this->data['controller']['class'].'::'.$this->data['controller']['method'].'()' : $this->data['controller']); |
153 } | 153 } |
154 | 154 |
155 public function lateCollect() | 155 public function lateCollect() |
156 { | 156 { |
157 $this->data = $this->cloneVar($this->data); | 157 $this->data = $this->cloneVar($this->data); |
158 } | 158 } |
159 | 159 |
160 public function reset() | 160 public function reset() |
161 { | 161 { |
162 $this->data = array(); | 162 $this->data = []; |
163 $this->controllers = new \SplObjectStorage(); | 163 $this->controllers = new \SplObjectStorage(); |
164 } | 164 } |
165 | 165 |
166 public function getMethod() | 166 public function getMethod() |
167 { | 167 { |
282 * | 282 * |
283 * @return array The parameters | 283 * @return array The parameters |
284 */ | 284 */ |
285 public function getRouteParams() | 285 public function getRouteParams() |
286 { | 286 { |
287 return isset($this->data['request_attributes']['_route_params']) ? $this->data['request_attributes']['_route_params']->getValue() : array(); | 287 return isset($this->data['request_attributes']['_route_params']) ? $this->data['request_attributes']['_route_params']->getValue() : []; |
288 } | 288 } |
289 | 289 |
290 /** | 290 /** |
291 * Gets the parsed controller. | 291 * Gets the parsed controller. |
292 * | 292 * |
325 } | 325 } |
326 } | 326 } |
327 | 327 |
328 public static function getSubscribedEvents() | 328 public static function getSubscribedEvents() |
329 { | 329 { |
330 return array( | 330 return [ |
331 KernelEvents::CONTROLLER => 'onKernelController', | 331 KernelEvents::CONTROLLER => 'onKernelController', |
332 KernelEvents::RESPONSE => 'onKernelResponse', | 332 KernelEvents::RESPONSE => 'onKernelResponse', |
333 ); | 333 ]; |
334 } | 334 } |
335 | 335 |
336 /** | 336 /** |
337 * {@inheritdoc} | 337 * {@inheritdoc} |
338 */ | 338 */ |
348 * | 348 * |
349 * @return array|string An array of controller data or a simple string | 349 * @return array|string An array of controller data or a simple string |
350 */ | 350 */ |
351 protected function parseController($controller) | 351 protected function parseController($controller) |
352 { | 352 { |
353 if (is_string($controller) && false !== strpos($controller, '::')) { | 353 if (\is_string($controller) && false !== strpos($controller, '::')) { |
354 $controller = explode('::', $controller); | 354 $controller = explode('::', $controller); |
355 } | 355 } |
356 | 356 |
357 if (is_array($controller)) { | 357 if (\is_array($controller)) { |
358 try { | 358 try { |
359 $r = new \ReflectionMethod($controller[0], $controller[1]); | 359 $r = new \ReflectionMethod($controller[0], $controller[1]); |
360 | 360 |
361 return array( | 361 return [ |
362 'class' => is_object($controller[0]) ? get_class($controller[0]) : $controller[0], | 362 'class' => \is_object($controller[0]) ? \get_class($controller[0]) : $controller[0], |
363 'method' => $controller[1], | 363 'method' => $controller[1], |
364 'file' => $r->getFileName(), | 364 'file' => $r->getFileName(), |
365 'line' => $r->getStartLine(), | 365 'line' => $r->getStartLine(), |
366 ); | 366 ]; |
367 } catch (\ReflectionException $e) { | 367 } catch (\ReflectionException $e) { |
368 if (is_callable($controller)) { | 368 if (\is_callable($controller)) { |
369 // using __call or __callStatic | 369 // using __call or __callStatic |
370 return array( | 370 return [ |
371 'class' => is_object($controller[0]) ? get_class($controller[0]) : $controller[0], | 371 'class' => \is_object($controller[0]) ? \get_class($controller[0]) : $controller[0], |
372 'method' => $controller[1], | 372 'method' => $controller[1], |
373 'file' => 'n/a', | 373 'file' => 'n/a', |
374 'line' => 'n/a', | 374 'line' => 'n/a', |
375 ); | 375 ]; |
376 } | 376 } |
377 } | 377 } |
378 } | 378 } |
379 | 379 |
380 if ($controller instanceof \Closure) { | 380 if ($controller instanceof \Closure) { |
381 $r = new \ReflectionFunction($controller); | 381 $r = new \ReflectionFunction($controller); |
382 | 382 |
383 return array( | 383 $controller = [ |
384 'class' => $r->getName(), | 384 'class' => $r->getName(), |
385 'method' => null, | 385 'method' => null, |
386 'file' => $r->getFileName(), | 386 'file' => $r->getFileName(), |
387 'line' => $r->getStartLine(), | 387 'line' => $r->getStartLine(), |
388 ); | 388 ]; |
389 } | 389 |
390 | 390 if (false !== strpos($r->name, '{closure}')) { |
391 if (is_object($controller)) { | 391 return $controller; |
392 } | |
393 $controller['method'] = $r->name; | |
394 | |
395 if ($class = $r->getClosureScopeClass()) { | |
396 $controller['class'] = $class->name; | |
397 } else { | |
398 return $r->name; | |
399 } | |
400 | |
401 return $controller; | |
402 } | |
403 | |
404 if (\is_object($controller)) { | |
392 $r = new \ReflectionClass($controller); | 405 $r = new \ReflectionClass($controller); |
393 | 406 |
394 return array( | 407 return [ |
395 'class' => $r->getName(), | 408 'class' => $r->getName(), |
396 'method' => null, | 409 'method' => null, |
397 'file' => $r->getFileName(), | 410 'file' => $r->getFileName(), |
398 'line' => $r->getStartLine(), | 411 'line' => $r->getStartLine(), |
399 ); | 412 ]; |
400 } | 413 } |
401 | 414 |
402 return is_string($controller) ? $controller : 'n/a'; | 415 return \is_string($controller) ? $controller : 'n/a'; |
403 } | 416 } |
404 } | 417 } |