Open Monograph Press  3.3.0
GuzzleHttp\HandlerStack Class Reference

Public Member Functions

 __construct (callable $handler=null)
 
 __invoke (RequestInterface $request, array $options)
 
 __toString ()
 
 after ($findName, callable $middleware, $withName='')
 
 before ($findName, callable $middleware, $withName='')
 
 hasHandler ()
 
 push (callable $middleware, $name='')
 
 remove ($remove)
 
 resolve ()
 
 setHandler (callable $handler)
 
 unshift (callable $middleware, $name=null)
 

Static Public Member Functions

static create (callable $handler=null)
 

Detailed Description

Creates a composed Guzzle handler function by stacking middlewares on top of an HTTP handler function.

Definition at line 12 of file HandlerStack.php.

Constructor & Destructor Documentation

◆ __construct()

GuzzleHttp\HandlerStack::__construct ( callable  $handler = null)
Parameters
callable$handlerUnderlying HTTP handler.

Definition at line 63 of file HandlerStack.php.

Member Function Documentation

◆ __invoke()

GuzzleHttp\HandlerStack::__invoke ( RequestInterface  $request,
array  $options 
)

Invokes the handler stack as a composed handler

Parameters
RequestInterface$request
array$options
Returns
ResponseInterface|PromiseInterface

Definition at line 76 of file HandlerStack.php.

◆ __toString()

GuzzleHttp\HandlerStack::__toString ( )

Dumps a string representation of the stack.

Returns
string

Definition at line 88 of file HandlerStack.php.

◆ after()

GuzzleHttp\HandlerStack::after (   $findName,
callable  $middleware,
  $withName = '' 
)

Add a middleware after another middleware by name.

Parameters
string$findNameMiddleware to find
callable$middlewareMiddleware function
string$withNameName to register for this middleware.

Definition at line 177 of file HandlerStack.php.

◆ before()

GuzzleHttp\HandlerStack::before (   $findName,
callable  $middleware,
  $withName = '' 
)

Add a middleware before another middleware by name.

Parameters
string$findNameMiddleware to find
callable$middlewareMiddleware function
string$withNameName to register for this middleware.

Definition at line 165 of file HandlerStack.php.

◆ create()

static GuzzleHttp\HandlerStack::create ( callable  $handler = null)
static

Creates a default handler stack that can be used by clients.

The returned handler will wrap the provided handler or use the most appropriate default handler for your system. The returned HandlerStack has support for cookies, redirects, HTTP error exceptions, and preparing a body before sending.

The returned handler stack can be passed to a client in the "handler" option.

Parameters
callable$handlerHTTP handler function to use with the stack. If no handler is provided, the best handler for your system will be utilized.
Returns
HandlerStack

Definition at line 49 of file HandlerStack.php.

References GuzzleHttp\choose_handler().

Referenced by GuzzleHttp\Handler\MockHandler\createWithMiddleware().

◆ hasHandler()

GuzzleHttp\HandlerStack::hasHandler ( )

Returns true if the builder has a handler.

Returns
bool

Definition at line 129 of file HandlerStack.php.

◆ push()

GuzzleHttp\HandlerStack::push ( callable  $middleware,
  $name = '' 
)

Push a middleware to the top of the stack.

Parameters
callable$middlewareMiddleware function
string$nameName to register for this middleware.

Definition at line 152 of file HandlerStack.php.

◆ remove()

GuzzleHttp\HandlerStack::remove (   $remove)

Remove a middleware by instance or name from the stack.

Parameters
callable | string$removeMiddleware to remove by instance or name.

Definition at line 187 of file HandlerStack.php.

◆ resolve()

GuzzleHttp\HandlerStack::resolve ( )

Compose the middleware and handler into a single callable function.

Returns
callable

Definition at line 204 of file HandlerStack.php.

◆ setHandler()

GuzzleHttp\HandlerStack::setHandler ( callable  $handler)

Set the HTTP handler that actually returns a promise.

Parameters
callable$handlerAccepts a request and array of options and returns a Promise.

Definition at line 118 of file HandlerStack.php.

◆ unshift()

GuzzleHttp\HandlerStack::unshift ( callable  $middleware,
  $name = null 
)

Unshift a middleware to the bottom of the stack.

Parameters
callable$middlewareMiddleware function
string$nameName to register for this middleware.

Definition at line 140 of file HandlerStack.php.


The documentation for this class was generated from the following file: