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