HandlerStack
in package
Creates a composed Guzzle handler function by stacking middlewares on top of an HTTP handler function.
Tags
Table of Contents
Properties
- $cached : callable(RequestInterface, array<string|int, mixed>): PromiseInterface|null
- $handler : callable(RequestInterface, array<string|int, mixed>): PromiseInterface|null
- $stack : array<string|int, array{: callable, : string|null}>
Methods
- __construct() : mixed
- __invoke() : ResponseInterface|PromiseInterface
- Invokes the handler stack as a composed handler
- __toString() : string
- Dumps a string representation of the stack.
- after() : void
- Add a middleware after another middleware by name.
- before() : void
- Add a middleware before another middleware by name.
- create() : self
- Creates a default handler stack that can be used by clients.
- hasHandler() : bool
- Returns true if the builder has a handler.
- push() : void
- Push a middleware to the top of the stack.
- remove() : void
- Remove a middleware by instance or name from the stack.
- resolve() : callable(RequestInterface, array<string|int, mixed>): PromiseInterface
- Compose the middleware and handler into a single callable function.
- setHandler() : void
- Set the HTTP handler that actually returns a promise.
- unshift() : void
- Unshift a middleware to the bottom of the stack.
- debugCallable() : string
- Provides a debug string for a given callable.
- findByName() : int
- splice() : void
- Splices a function into the middleware list at a specific position.
Properties
$cached
private
callable(RequestInterface, array<string|int, mixed>): PromiseInterface|null
$cached
$handler
private
callable(RequestInterface, array<string|int, mixed>): PromiseInterface|null
$handler
$stack
private
array<string|int, array{: callable, : string|null}>
$stack
= []
Methods
__construct()
public
__construct([callable(RequestInterface, array<string|int, mixed>): PromiseInterface|null $handler = null ]) : mixed
Parameters
- $handler : callable(RequestInterface, array<string|int, mixed>): PromiseInterface|null = null
-
Underlying HTTP handler.
__invoke()
Invokes the handler stack as a composed handler
public
__invoke(RequestInterface $request, array<string|int, mixed> $options) : ResponseInterface|PromiseInterface
Parameters
- $request : RequestInterface
- $options : array<string|int, mixed>
Return values
ResponseInterface|PromiseInterface__toString()
Dumps a string representation of the stack.
public
__toString() : string
Return values
stringafter()
Add a middleware after another middleware by name.
public
after(string $findName, callable(callable): callable $middleware[, string $withName = '' ]) : void
Parameters
- $findName : string
-
Middleware to find
- $middleware : callable(callable): callable
-
Middleware function
- $withName : string = ''
-
Name to register for this middleware.
before()
Add a middleware before another middleware by name.
public
before(string $findName, callable(callable): callable $middleware[, string $withName = '' ]) : void
Parameters
- $findName : string
-
Middleware to find
- $middleware : callable(callable): callable
-
Middleware function
- $withName : string = ''
-
Name to register for this middleware.
create()
Creates a default handler stack that can be used by clients.
public
static create([callable(RequestInterface, array<string|int, mixed>): PromiseInterface|null $handler = null ]) : self
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
- $handler : callable(RequestInterface, array<string|int, mixed>): PromiseInterface|null = null
-
HTTP handler function to use with the stack. If no handler is provided, the best handler for your system will be utilized.
Return values
selfhasHandler()
Returns true if the builder has a handler.
public
hasHandler() : bool
Return values
boolpush()
Push a middleware to the top of the stack.
public
push(callable(callable): callable $middleware[, string $name = '' ]) : void
Parameters
- $middleware : callable(callable): callable
-
Middleware function
- $name : string = ''
-
Name to register for this middleware.
remove()
Remove a middleware by instance or name from the stack.
public
remove(callable|string $remove) : void
Parameters
- $remove : callable|string
-
Middleware to remove by instance or name.
resolve()
Compose the middleware and handler into a single callable function.
public
resolve() : callable(RequestInterface, array<string|int, mixed>): PromiseInterface
Return values
callable(RequestInterface, array<string|int, mixed>): PromiseInterfacesetHandler()
Set the HTTP handler that actually returns a promise.
public
setHandler(callable(RequestInterface, array<string|int, mixed>): PromiseInterface $handler) : void
Parameters
- $handler : callable(RequestInterface, array<string|int, mixed>): PromiseInterface
-
Accepts a request and array of options and returns a Promise.
unshift()
Unshift a middleware to the bottom of the stack.
public
unshift(callable(callable): callable $middleware[, string $name = null ]) : void
Parameters
- $middleware : callable(callable): callable
-
Middleware function
- $name : string = null
-
Name to register for this middleware.
debugCallable()
Provides a debug string for a given callable.
private
debugCallable(callable|string $fn) : string
Parameters
- $fn : callable|string
-
Function to write as a string.
Return values
stringfindByName()
private
findByName(string $name) : int
Parameters
- $name : string
Return values
intsplice()
Splices a function into the middleware list at a specific position.
private
splice(string $findName, string $withName, callable $middleware, bool $before) : void
Parameters
- $findName : string
- $withName : string
- $middleware : callable
- $before : bool