Class HandlerList
- Aws\HandlerList implements Countable
- Namespace: Aws
- Located at HandlerList.php
Builds a single handler function from zero or more middleware functions and a handler. The handler function is then used to send command objects and return a promise that is resolved with an AWS result object.
The "front" of the list is invoked before the "end" of the list. You can add middleware to the front of the list using one of the "prepend" method, and the end of the list using one of the "append" method. The last function invoked in a handler list is the handler (a function that does not accept a next handler but rather is responsible for returning a promise that is fulfilled with an Aws\ResultInterface object).
Handlers are ordered using a "step" that describes the step at which the SDK is when sending a command. The available steps are:
- init: The command is being initialized, allowing you to do things like add default options.
- validate: The command is being validated before it is serialized
- build: The command is being serialized into an HTTP request. A middleware in this step MUST serialize an HTTP request and populate the "@request" parameter of a command with the request such that it is available to subsequent middleware.
- sign: The request is being signed and prepared to be sent over the wire.
Middleware can be registered with a name to allow you to easily add a middleware before or after another middleware by name. This also allows you to remove a middleware by name (in addition to removing by instance).
Methods Summary
- __construct ( callable $handler = null )
-
__toString ( )
Dumps a string representation of the list.
-
setHandler ( callable $handler )
Set the HTTP handler that actually returns a response.
-
hasHandler ( )
Returns true if the builder has a handler.
-
appendInit ( callable $middleware, string $name = null )
Append a middleware to the init step.
-
prependInit ( callable $middleware, string $name = null )
Prepend a middleware to the init step.
-
appendValidate ( callable $middleware, string $name = null )
Append a middleware to the validate step.
-
prependValidate ( callable $middleware, string $name = null )
Prepend a middleware to the validate step.
-
appendBuild ( callable $middleware, string $name = null )
Append a middleware to the build step.
-
prependBuild ( callable $middleware, string $name = null )
Prepend a middleware to the build step.
-
appendSign ( callable $middleware, string $name = null )
Append a middleware to the sign step.
-
prependSign ( callable $middleware, string $name = null )
Prepend a middleware to the sign step.
-
appendAttempt ( callable $middleware, string $name = null )
Append a middleware to the attempt step.
-
prependAttempt ( callable $middleware, string $name = null )
Prepend a middleware to the attempt step.
-
before ( string|callable $findName, string $withName, callable $middleware )
Add a middleware before the given middleware by name.
-
after ( string|callable $findName, string $withName, callable $middleware )
Add a middleware after the given middleware by name.
-
remove ( string|callable $nameOrInstance )
Remove a middleware by name or by instance from the list.
-
interpose ( callable $fn = null )
Interpose a function between each middleware (e.g., allowing for a trace through the middleware layers).
-
resolve ( )
Compose the middleware and handler into a single callable function.
- count ( )
Methods Details
__construct ( callable $handler = null )
Parameters
callable | $handler = null | HTTP handler. |
string __toString ( )
Dumps a string representation of the list.
Returns
string |
setHandler ( callable $handler )
Set the HTTP handler that actually returns a response.
Parameters
callable | $handler | Function that accepts a request and array of options and returns a Promise. |
boolean hasHandler ( )
Returns true if the builder has a handler.
Returns
boolean |
appendInit ( callable $middleware, string $name = null )
Append a middleware to the init step.
Parameters
callable | $middleware | Middleware function to add. |
string | $name = null | Name of the middleware. |
prependInit ( callable $middleware, string $name = null )
Prepend a middleware to the init step.
Parameters
callable | $middleware | Middleware function to add. |
string | $name = null | Name of the middleware. |
appendValidate ( callable $middleware, string $name = null )
Append a middleware to the validate step.
Parameters
callable | $middleware | Middleware function to add. |
string | $name = null | Name of the middleware. |
prependValidate ( callable $middleware, string $name = null )
Prepend a middleware to the validate step.
Parameters
callable | $middleware | Middleware function to add. |
string | $name = null | Name of the middleware. |
appendBuild ( callable $middleware, string $name = null )
Append a middleware to the build step.
Parameters
callable | $middleware | Middleware function to add. |
string | $name = null | Name of the middleware. |
prependBuild ( callable $middleware, string $name = null )
Prepend a middleware to the build step.
Parameters
callable | $middleware | Middleware function to add. |
string | $name = null | Name of the middleware. |
appendSign ( callable $middleware, string $name = null )
Append a middleware to the sign step.
Parameters
callable | $middleware | Middleware function to add. |
string | $name = null | Name of the middleware. |
prependSign ( callable $middleware, string $name = null )
Prepend a middleware to the sign step.
Parameters
callable | $middleware | Middleware function to add. |
string | $name = null | Name of the middleware. |
appendAttempt ( callable $middleware, string $name = null )
Append a middleware to the attempt step.
Parameters
callable | $middleware | Middleware function to add. |
string | $name = null | Name of the middleware. |
prependAttempt ( callable $middleware, string $name = null )
Prepend a middleware to the attempt step.
Parameters
callable | $middleware | Middleware function to add. |
string | $name = null | Name of the middleware. |
before ( string|callable $findName, string $withName, callable $middleware )
Add a middleware before the given middleware by name.
Parameters
string|callable | $findName | Add before this |
string | $withName | Optional name to give the middleware |
callable | $middleware | Middleware to add. |
after ( string|callable $findName, string $withName, callable $middleware )
Add a middleware after the given middleware by name.
Parameters
string|callable | $findName | Add after this |
string | $withName | Optional name to give the middleware |
callable | $middleware | Middleware to add. |
remove ( string|callable $nameOrInstance )
Remove a middleware by name or by instance from the list.
Parameters
string|callable | $nameOrInstance | Middleware to remove. |
interpose ( callable $fn = null )
Interpose a function between each middleware (e.g., allowing for a trace through the middleware layers).
The interpose function is a function that accepts a "step" argument as a string and a "name" argument string. This function must then return a function that accepts the next handler in the list. This function must then return a function that accepts a CommandInterface and optional RequestInterface and returns a promise that is fulfilled with an Aws\ResultInterface or rejected with an Aws\Exception\AwsException object.
Parameters
callable | $fn = null | Pass null to remove any previously set function |
callable resolve ( )
Compose the middleware and handler into a single callable function.
Returns
callable |
count ( )
Implementation of
Countable::count()
Constants summary
string |
INIT
|
#
'init'
|
string |
VALIDATE
|
#
'validate'
|
string |
BUILD
|
#
'build'
|
string |
SIGN
|
#
'sign'
|
string |
ATTEMPT
|
#
'attempt'
|