Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / EventSubscriber / ExceptionTestSiteSubscriber.php
1 <?php
2
3 namespace Drupal\Core\EventSubscriber;
4
5 use Drupal\Core\Utility\Error;
6 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
7
8 /**
9  * Custom handling of errors when in a system-under-test.
10  */
11 class ExceptionTestSiteSubscriber extends HttpExceptionSubscriberBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   protected static function getPriority() {
17     return 3;
18   }
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function getHandledFormats() {
24     return ['html'];
25   }
26
27   /**
28    * Checks for special handling of errors inside Simpletest.
29    *
30    * @todo The $headers array appears to not actually get used at all in the
31    *   original code. It's quite possible that this entire method is now
32    *   vestigial and can be removed.
33    *
34    * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
35    */
36   public function on500(GetResponseForExceptionEvent $event) {
37     $exception = $event->getException();
38     $error = Error::decodeException($exception);
39
40     $headers = [];
41
42     // When running inside the testing framework, we relay the errors
43     // to the tested site by the way of HTTP headers.
44     if (DRUPAL_TEST_IN_CHILD_SITE && !headers_sent() && (!defined('SIMPLETEST_COLLECT_ERRORS') || SIMPLETEST_COLLECT_ERRORS)) {
45       // $number does not use drupal_static as it should not be reset
46       // as it uniquely identifies each PHP error.
47       static $number = 0;
48       $assertion = [
49         $error['@message'],
50         $error['%type'],
51         [
52           'function' => $error['%function'],
53           'file' => $error['%file'],
54           'line' => $error['%line'],
55         ],
56       ];
57       $headers['X-Drupal-Assertion-' . $number] = rawurlencode(serialize($assertion));
58       $number++;
59     }
60   }
61
62 }