TestMiddleware.php in Zircon Profile 8
File
core/modules/system/tests/modules/httpkernel_test/src/HttpKernel/TestMiddleware.php
View source
<?php
namespace Drupal\httpkernel_test\HttpKernel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class TestMiddleware implements HttpKernelInterface {
protected $kernel;
protected $optionalArgument;
public function __construct(HttpKernelInterface $kernel, $optional_argument = NULL) {
$this->kernel = $kernel;
$this->optionalArgument = $optional_argument;
}
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);
}
}