You are here

class MonkeysInTheControlRoom in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php \Drupal\error_service_test\MonkeysInTheControlRoom
  2. 9 core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php \Drupal\error_service_test\MonkeysInTheControlRoom

A http middleware designed to cause bedlam.

Hierarchy

  • class \Drupal\error_service_test\MonkeysInTheControlRoom implements \Symfony\Component\HttpKernel\HttpKernelInterface

Expanded class hierarchy of MonkeysInTheControlRoom

See also

error_service_test.services.yml

1 string reference to 'MonkeysInTheControlRoom'
error_service_test.services.yml in core/modules/system/tests/modules/error_service_test/error_service_test.services.yml
core/modules/system/tests/modules/error_service_test/error_service_test.services.yml
1 service uses MonkeysInTheControlRoom
http_middleware.monkeys in core/modules/system/tests/modules/error_service_test/error_service_test.services.yml
Drupal\error_service_test\MonkeysInTheControlRoom

File

core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php, line 15

Namespace

Drupal\error_service_test
View source
class MonkeysInTheControlRoom implements HttpKernelInterface {

  /**
   * The app kernel.
   *
   * @var \Symfony\Component\HttpKernel\HttpKernelInterface
   */
  protected $app;

  /**
   * MonkeysInTheControlRoom constructor.
   *
   * @param \Symfony\Component\HttpKernel\HttpKernelInterface $app
   *   The wrapper HTTP kernel.
   * @param \Drupal\Core\Site\Settings $settings
   *   The settings object.
   */
  public function __construct(HttpKernelInterface $app, Settings $settings) {
    $this->app = $app;
    $this->settings = $settings;
  }

  /**
   * {@inheritdoc}
   */
  public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = TRUE) : Response {
    if (\Drupal::state()
      ->get('error_service_test.break_bare_html_renderer')) {

      // Let the bedlam begin.
      // 1) Force a container rebuild.

      /** @var \Drupal\Core\DrupalKernelInterface $kernel */
      $kernel = \Drupal::service('kernel');
      $kernel
        ->rebuildContainer();

      // 2) Fetch the in-situ container builder.
      $container = ErrorServiceTestServiceProvider::$containerBuilder;

      // Ensure the compiler pass worked.
      if (!$container) {
        throw new \Exception('Oh oh, monkeys stole the ServiceProvider.');
      }

      // Stop the theme manager from being found - and triggering error
      // maintenance mode.
      $container
        ->removeDefinition('theme.manager');

      // Mash. Mash. Mash.
      \Drupal::setContainer($container);
      throw new \Exception('Oh oh, bananas in the instruments.');
    }
    if (\Drupal::state()
      ->get('error_service_test.break_logger')) {
      throw new \Exception('Deforestation');
    }
    if ($this->settings
      ->get('teapots', FALSE) && class_exists('\\TypeError')) {
      try {
        $return = $this->app
          ->handle($request, $type, $catch);
      } catch (\TypeError $e) {
        header('HTTP/1.1 418 I\'m a teapot');
        print 'Oh oh, flying teapots';
        exit;
      }
    }
    else {
      $return = $this->app
        ->handle($request, $type, $catch);
    }
    return $return;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MonkeysInTheControlRoom::$app protected property The app kernel.
MonkeysInTheControlRoom::handle public function
MonkeysInTheControlRoom::__construct public function MonkeysInTheControlRoom constructor.