public function MonkeysInTheControlRoom::handle in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php \Drupal\error_service_test\MonkeysInTheControlRoom::handle()
Handles a Request to convert it to a Response.
When $catch is true, the implementation must catch all exceptions and do its best to convert them to a Response instance.
Parameters
Request $request A Request instance:
int $type The type of the request: (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
bool $catch Whether to catch exceptions or not:
Return value
Response A Response instance
Throws
\Exception When an Exception occurs during processing
Overrides HttpKernelInterface::handle
File
- core/
modules/ system/ tests/ modules/ error_service_test/ src/ MonkeysInTheControlRoom.php, line 41 - Contains \Drupal\error_service_test\MonkeysInTheControlRoom.
Class
- MonkeysInTheControlRoom
- A http middleware designed to cause bedlam.
Namespace
Drupal\error_service_testCode
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
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;
}