MonkeysInTheControlRoom.php in Drupal 9
File
core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php
View source
<?php
namespace Drupal\error_service_test;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class MonkeysInTheControlRoom implements HttpKernelInterface {
protected $app;
public function __construct(HttpKernelInterface $app, Settings $settings) {
$this->app = $app;
$this->settings = $settings;
}
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
if (\Drupal::state()
->get('error_service_test.break_bare_html_renderer')) {
$kernel = \Drupal::service('kernel');
$kernel
->rebuildContainer();
$container = ErrorServiceTestServiceProvider::$containerBuilder;
if (!$container) {
throw new \Exception('Oh oh, monkeys stole the ServiceProvider.');
}
$container
->removeDefinition('theme.manager');
\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;
}
}