SDK for PHP 3.x

HandlerList
in package
implements Countable

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).

Table of Contents

Interfaces

Countable

Constants

ATTEMPT  = 'attempt'
BUILD  = 'build'
INIT  = 'init'
SIGN  = 'sign'
VALIDATE  = 'validate'

Methods

__construct()  : mixed
__toString()  : string
Dumps a string representation of the list.
after()  : mixed
Add a middleware after the given middleware by name.
appendAttempt()  : mixed
Append a middleware to the attempt step.
appendBuild()  : mixed
Append a middleware to the build step.
appendInit()  : mixed
Append a middleware to the init step.
appendSign()  : mixed
Append a middleware to the sign step.
appendValidate()  : mixed
Append a middleware to the validate step.
before()  : mixed
Add a middleware before the given middleware by name.
count()  : int
hasHandler()  : bool
Returns true if the builder has a handler.
interpose()  : mixed
Interpose a function between each middleware (e.g., allowing for a trace through the middleware layers).
prependAttempt()  : mixed
Prepend a middleware to the attempt step.
prependBuild()  : mixed
Prepend a middleware to the build step.
prependInit()  : mixed
Prepend a middleware to the init step.
prependSign()  : mixed
Prepend a middleware to the sign step.
prependValidate()  : mixed
Prepend a middleware to the validate step.
remove()  : mixed
Remove a middleware by name or by instance from the list.
resolve()  : callable
Compose the middleware and handler into a single callable function.
setHandler()  : mixed
Set the HTTP handler that actually returns a response.

Constants

ATTEMPT

public mixed ATTEMPT = 'attempt'

BUILD

public mixed BUILD = 'build'

INIT

public mixed INIT = 'init'

SIGN

public mixed SIGN = 'sign'

VALIDATE

public mixed VALIDATE = 'validate'

Methods

__construct()

public __construct([callable $handler = null ]) : mixed
Parameters
$handler : callable = null

HTTP handler.

__toString()

Dumps a string representation of the list.

public __toString() : string
Return values
string

after()

Add a middleware after the given middleware by name.

public after(string|callable $findName, string $withName, callable $middleware) : mixed
Parameters
$findName : string|callable

Add after this

$withName : string

Optional name to give the middleware

$middleware : callable

Middleware to add.

appendAttempt()

Append a middleware to the attempt step.

public appendAttempt(callable $middleware[, string $name = null ]) : mixed
Parameters
$middleware : callable

Middleware function to add.

$name : string = null

Name of the middleware.

appendBuild()

Append a middleware to the build step.

public appendBuild(callable $middleware[, string $name = null ]) : mixed
Parameters
$middleware : callable

Middleware function to add.

$name : string = null

Name of the middleware.

appendInit()

Append a middleware to the init step.

public appendInit(callable $middleware[, string $name = null ]) : mixed
Parameters
$middleware : callable

Middleware function to add.

$name : string = null

Name of the middleware.

appendSign()

Append a middleware to the sign step.

public appendSign(callable $middleware[, string $name = null ]) : mixed
Parameters
$middleware : callable

Middleware function to add.

$name : string = null

Name of the middleware.

appendValidate()

Append a middleware to the validate step.

public appendValidate(callable $middleware[, string $name = null ]) : mixed
Parameters
$middleware : callable

Middleware function to add.

$name : string = null

Name of the middleware.

before()

Add a middleware before the given middleware by name.

public before(string|callable $findName, string $withName, callable $middleware) : mixed
Parameters
$findName : string|callable

Add before this

$withName : string

Optional name to give the middleware

$middleware : callable

Middleware to add.

count()

public count() : int
Return values
int

hasHandler()

Returns true if the builder has a handler.

public hasHandler() : bool
Return values
bool

interpose()

Interpose a function between each middleware (e.g., allowing for a trace through the middleware layers).

public interpose([callable|null $fn = null ]) : mixed

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
$fn : callable|null = null

Pass null to remove any previously set function

prependAttempt()

Prepend a middleware to the attempt step.

public prependAttempt(callable $middleware[, string $name = null ]) : mixed
Parameters
$middleware : callable

Middleware function to add.

$name : string = null

Name of the middleware.

prependBuild()

Prepend a middleware to the build step.

public prependBuild(callable $middleware[, string $name = null ]) : mixed
Parameters
$middleware : callable

Middleware function to add.

$name : string = null

Name of the middleware.

prependInit()

Prepend a middleware to the init step.

public prependInit(callable $middleware[, string $name = null ]) : mixed
Parameters
$middleware : callable

Middleware function to add.

$name : string = null

Name of the middleware.

prependSign()

Prepend a middleware to the sign step.

public prependSign(callable $middleware[, string $name = null ]) : mixed
Parameters
$middleware : callable

Middleware function to add.

$name : string = null

Name of the middleware.

prependValidate()

Prepend a middleware to the validate step.

public prependValidate(callable $middleware[, string $name = null ]) : mixed
Parameters
$middleware : callable

Middleware function to add.

$name : string = null

Name of the middleware.

remove()

Remove a middleware by name or by instance from the list.

public remove(string|callable $nameOrInstance) : mixed
Parameters
$nameOrInstance : string|callable

Middleware to remove.

resolve()

Compose the middleware and handler into a single callable function.

public resolve() : callable
Return values
callable

setHandler()

Set the HTTP handler that actually returns a response.

public setHandler(callable $handler) : mixed
Parameters
$handler : callable

Function that accepts a request and array of options and returns a Promise.

On this page