You are here

public function TestMiddleware::handle in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/modules/httpkernel_test/src/HttpKernel/TestMiddleware.php \Drupal\httpkernel_test\HttpKernel\TestMiddleware::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/httpkernel_test/src/HttpKernel/TestMiddleware.php, line 48
Contains \Drupal\httpkernel_test\HttpKernel\TestMiddleware.

Class

TestMiddleware
Provides a test middleware.

Namespace

Drupal\httpkernel_test\HttpKernel

Code

public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
  $request->attributes
    ->set('_hello', 'world');
  if ($request->attributes
    ->has('_optional_argument')) {
    $request->attributes
      ->set('_previous_optional_argument', $request->attributes
      ->get('_optional_argument'));
  }
  elseif (isset($this->optionalArgument)) {
    $request->attributes
      ->set('_optional_argument', $this->optionalArgument);
  }
  return $this->kernel
    ->handle($request, $type, $catch);
}