function HandlerStackConfigurator::initializeMiddlewares

Same name in other branches
  1. 9 core/lib/Drupal/Core/Http/HandlerStackConfigurator.php \Drupal\Core\Http\HandlerStackConfigurator::initializeMiddlewares()
  2. 8.9.x core/lib/Drupal/Core/Http/HandlerStackConfigurator.php \Drupal\Core\Http\HandlerStackConfigurator::initializeMiddlewares()
  3. 11.x 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 61

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.');
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.