public function HttpMiddleware::__invoke in File Link 2.0.x
Invoked method that returns a promise.
File
- tests/
modules/ file_link_test/ src/ HttpMiddleware.php, line 28
Class
- HttpMiddleware
- A middleware for guzzle to test requests.
Namespace
Drupal\file_link_testCode
public function __invoke() {
return function ($handler) {
return function (RequestInterface $request, array $options) use ($handler) {
$uri = $request
->getUri();
$settings = Settings::get('file_link_test_middleware', []);
// Check if the request is made to one of our fixtures.
$key = $uri
->getScheme() . '://' . $uri
->getHost() . $uri
->getPath();
if (array_key_exists($key, $settings)) {
if (!isset(static::$recorder[$key])) {
static::$recorder[$key] = 0;
}
static::$recorder[$key]++;
return $this
->createPromise($request, $settings[$key]);
}
// Otherwise, no intervention. We defer to the handler stack.
return $handler($request, $options);
};
};
}