Build a handler stack.

@return \GuzzleHttp\HandlerStack
165605
public function getHandlerStack(): HandlerStack
    {
        if ($this->handlerStack) {
            return $this->handlerStack;
        }

        $this->handlerStack = HandlerStack::create($this->getGuzzleHandler());

        foreach ($this->middlewares as $name => $middleware) {
            $this->handlerStack->push($middleware, $name);
        }

        return $this->handlerStack;
    }
1188936
public static function build() {
        try {
            self::init();
            self::dependencies();
    
            $route = self::canRoute();
    
            if ($route !== false) {
                $actionContext = self::actionContext($route);
    
                if ($actionContext !== null && !self::cached($actionContext)) {
                    self::filters($actionContext);
                    self::headers();
                    self::validation();
                    self::render($actionContext);
                }
            }
        }
        catch (\Exception $ex) {
            $errorHandlerEventArgs = new ErrorHandlerEventArgs($ex);
            self::invokeAll(self::$appContext->getErrorHandler(), array($errorHandlerEventArgs));

            if ($errorHandlerEventArgs->getHandled() !== true) {
                throw $ex;
            }
        }
    }
366029
protected function buildControlHandlerLoop() {
        $controlHandlerCases = $this->buildControlHandlerCases();
        $result = '';
        if (!empty($controlHandlerCases)) {
            $result = '        foreach (Event in PendingEvents) {' . PHP_EOL
                    . '            switch (Event.Type) {' . PHP_EOL
                    . $controlHandlerCases
                    . '            }' . PHP_EOL
                    . '        }' . PHP_EOL;
        }
        return $result;
    }
998583
public static function create()
    {
        $dispatcher = new Dispatcher();
        foreach (static::$_stack as $middleware) {
            $dispatcher->addFilter($middleware);
        }

        return $dispatcher;
    }
913914
protected function getHandler()
    {
        $stack = HandlerStack::create();

        foreach ($this->middlewares as $middleware) {
            $stack->push($middleware);
        }

        if (isset(static::$defaults['handler']) && is_callable(static::$defaults['handler'])) {
            $stack->push(static::$defaults['handler'], self::USER_DEFINED_HANDLER);
        }

        return $stack;
    }
378730
public function push(){
		if($this->depth > 0){
			// Make sure the parent is loaded before creating a new one
			$this->loadCurrent();
			// Now set loaded back to false as the new one isn't
			$this->loaded = false;
		}
		
		$selector = Selector::create();
		
		if(count($this->stack) > $this->depth){
			$this->stack[$this->depth][] = $selector;
		}else{
			$this->stack[] = [$selector];
		}
		$this->depth++;
		
		return $selector;
	}
1011090
public function createDefaultHttpClient()
    {
        $stack = HandlerStack::create();

        $middleware = new Oauth1([
            'consumer_key'    => $this->consumerKey,
            'consumer_secret' => $this->consumerSecret,
            'token'           => $this->token,
            'token_secret'    => $this->tokenSecret
        ]);

        $stack->push($middleware);

        return new HttpClient([
            'handler' => $stack
        ]);
    }
762679
public function createStack($handlers): Stack
    {
        if (!is_array($handlers)) {
            $handlers = [$handlers];
        }
        return new Stack(
            $handlers,
            $this->handlerResolver
        );
    }
627069
public function parentStack() {
        $p=$this->owner;
        
        while($p) {
            $stack[]=$p;
            if($p->FolderID && $p->FolderID>0) {
                $folder=$p->Folder();
                if(!empty($folder) && $folder!==false && $folder->ID!=0) {
                    $p=$folder;
                }
            }else {
                $p=$p->LanguageID ? $p->Language() : null;
            }
        }
        
        return $stack;
    }
735980
public function build()
    {
        if ($this->handler) {
            $handler = $this->handler;
        } elseif ($this->pdo || $this->dbCredentials) {
            $options = $this->dbCredentials;
            $options['table'] = $this->table;
            if ($this->pdo) {
                $options['pdo'] = $this->pdo;
            }
            $handler = new PdoHandler($options);
        } else {
            $handler = new FileHandler($this->locking);
        }
        return new Session($handler, $this->name, $this->savePath, $this->serializer);
    }
281399
protected function createHandler()
    {
        $stack = HandlerStack::create();

        $stack->push(Middleware::mapRequest(function (RequestInterface $request) {
            $config = $this->config;

            if ($idempotencykey = $config->getIdempotencyKey()) {
                $request = $request->withHeader('Idempotency-Key', $idempotencykey);
            }

            if ($accountId = $config->getAccountId()) {
                $request = $request->withHeader('Stripe-Account', $accountId);
            }

            $request = $request->withHeader('Stripe-Version', $config->getApiVersion());

            $request = $request->withHeader('User-Agent', 'Cartalyst-Stripe/'.$config->getVersion());

            $request = $request->withHeader('Authorization', 'Basic '.base64_encode($config->getApiKey()));

            return $request;
        }));

        $stack->push(Middleware::retry(function ($retries, RequestInterface $request, ResponseInterface $response = null, TransferException $exception = null) {
            return $retries < 3 && ($exception instanceof ConnectException || ($response && $response->getStatusCode() >= 500));
        }, function ($retries) {
            return (int) pow(2, $retries) * 1000;
        }));

        return $stack;
    }
1176508
private function refresh()
    {
        $this->setHandler($this->config->get('logging.default', 'stack'));

        $this->messages = [
            'handler' => '',
            'files'   => [],
        ];
        $this->files    = [];

        $this->checkHandler();
        $this->checkLogFiles();

        return $this;
    }
1200522
public function generateHttpClient()
    {
        $config = $this->config;
        if (!array_key_exists('handler', $config)
            || $config['handler'] === null) {
            $config['handler'] = HandlerStack::create();
        }

        // Add a logging middleware required by this library.
        $config['handler']->before(
            'http_errors',
            GuzzleLogMessageHandler::log($this->logger, $this->messageFormatter)
        );

        return new Client($config);
    }
373109
public function afterDetach()
    {
        $handler = $this->get('handler');
        if (class_exists($handler)) {
            $handler = new $handler();

            return $handler->afterDetach($this);
        }
    }
1295084
private function handle(){
        $params = [
            "start"     => null,
            "finish"    => null,
            "response"  => null,
            "error"     => null,
        ];

        try{
            $params["start"]    = microtime(true);
            $params["response"] = $this->handler->handle($this->request);
        }catch(\Throwable $e){
            $params["error"]    = $e;
            $this->error        = $e;
        }finally{
            $params["finish"]   = microtime(true);
        }

        $this->event(new Event("response.handle.after", $params));

        return $params["response"];
    }
251636
public function getRequestHandlerBuilder(){
        if(null === $this->requestHandlerBuilder){
            $this->requestHandlerBuilder    = new RequestHandlerBuilder(
                $this->getContainer()
            );

            foreach($this->bundles as $bundle){
                if($bundle instanceof Bundle\MiddlewareRegisterInterface){
                    $bundle->middlewareRegister($this->requestHandlerBuilder);
                }
            }
        }

        return clone $this->requestHandlerBuilder;
    }
429964
protected function carry()
    {
        return function ($stack, $pipe) {
            return function ($passable) use ($stack, $pipe) {
                try {
                    $slice = parent::carry();

                    return \call_user_func($slice($stack, $pipe), $passable);
                } catch (Exception $e) {
                    return $this->handleException($passable, $e);
                } catch (Throwable $e) {
                    return $this->handleException($passable, new FatalThrowableError($e));
                }
            };
        };
    }