Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / system / tests / modules / error_service_test / src / MonkeysInTheControlRoom.php
1 <?php
2
3 namespace Drupal\error_service_test;
4
5 use Drupal\Core\Site\Settings;
6 use Symfony\Component\HttpFoundation\Request;
7 use Symfony\Component\HttpKernel\HttpKernelInterface;
8
9 /**
10  * A http middleware designed to cause bedlam.
11  *
12  * @see error_service_test.services.yml
13  */
14 class MonkeysInTheControlRoom implements HttpKernelInterface {
15
16   /**
17    * The app kernel.
18    *
19    * @var \Symfony\Component\HttpKernel\HttpKernelInterface
20    */
21   protected $app;
22
23   /**
24    * MonkeysInTheControlRoom constructor.
25    *
26    * @param \Symfony\Component\HttpKernel\HttpKernelInterface $app
27    *   The wrapper HTTP kernel.
28    */
29   public function __construct(HttpKernelInterface $app, Settings $settings) {
30     $this->app = $app;
31     $this->settings = $settings;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
38     if (\Drupal::state()->get('error_service_test.break_bare_html_renderer')) {
39       // Let the bedlam begin.
40       // 1) Force a container rebuild.
41       /** @var \Drupal\Core\DrupalKernelInterface $kernel */
42       $kernel = \Drupal::service('kernel');
43       $kernel->rebuildContainer();
44       // 2) Fetch the in-situ container builder.
45       $container = ErrorServiceTestServiceProvider::$containerBuilder;
46       // Ensure the compiler pass worked.
47       if (!$container) {
48         throw new \Exception('Oh oh, monkeys stole the ServiceProvider.');
49       }
50       // Stop the theme manager from being found - and triggering error
51       // maintenance mode.
52       $container->removeDefinition('theme.manager');
53       // Mash. Mash. Mash.
54       \Drupal::setContainer($container);
55       throw new \Exception('Oh oh, bananas in the instruments.');
56     }
57
58     if (\Drupal::state()->get('error_service_test.break_logger')) {
59       throw new \Exception('Deforestation');
60     }
61
62     if ($this->settings->get('teapots', FALSE) && class_exists('\TypeError')) {
63       try {
64         $return = $this->app->handle($request, $type, $catch);
65       }
66       catch (\TypeError $e) {
67         header('HTTP/1.1 418 I\'m a teapot');
68         print('Oh oh, flying teapots');
69         exit;
70       }
71     }
72     else {
73       $return = $this->app->handle($request, $type, $catch);
74     }
75     return $return;
76   }
77
78 }