You are here

protected function HandlerStackConfigurator::initializeMiddlewares in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Http/HandlerStackConfigurator.php \Drupal\Core\Http\HandlerStackConfigurator::initializeMiddlewares()

Ensures that the middlewares are initialized.

1 call to HandlerStackConfigurator::initializeMiddlewares()
HandlerStackConfigurator::configure in core/lib/Drupal/Core/Http/HandlerStackConfigurator.php
Configures the stack using services tagged as http_client_middleware.

File

core/lib/Drupal/Core/Http/HandlerStackConfigurator.php, line 66
Contains \Drupal\Core\Http\HandlerStackConfigurator.

Class

HandlerStackConfigurator
Defines a class for configuring middlewares on the http handler stack.

Namespace

Drupal\Core\Http

Code

protected function initializeMiddlewares() {
  if (!isset($this->middlewares)) {
    $this->middlewares = [];
    foreach ($this->middlewareIds as $middleware_id) {
      $middleware = $this->container
        ->get($middleware_id);
      if (is_callable($middleware)) {
        $this->middlewares[$middleware_id] = $middleware();
      }
      else {
        throw new \InvalidArgumentException('Middlewares need to implement __invoke, see https://guzzle.readthedocs.org/en/latest/handlers-and-middleware.html for more information about middlewares.');
      }
    }
  }
}