\Charcoal\App\ActionAbstractAction

Default implementation, as abstract class, of the `ActionInterface`.

Actions respond to a (PSR7-style) request and response and returns back the response.

Typical implementations only need to implement the following 2 abstract methods:

// Returns an associative array of results
public function results();
// Gets a psr7 request and response and returns a response
public function run(RequestInterface $request, ResponseInterface $response);

Actions can be invoked (with the magic __invoke() method) which automatically call the:

Summary

Methods
Properties
Constants
__construct()
init()
setDependencies()
__invoke()
setMode()
mode()
setSuccess()
success()
setSuccessUrl()
successUrl()
setFailureUrl()
failureUrl()
redirectUrl()
results()
run()
No public properties found
MODE_JSON
MODE_XML
MODE_REDIRECT
DEFAULT_MODE
No protected methods found
No protected properties found
N/A
No private methods found
$mode
$success
$successUrl
$failureUrl
N/A

Constants

MODE_JSON

MODE_JSON

MODE_XML

MODE_XML

MODE_REDIRECT

MODE_REDIRECT

DEFAULT_MODE

DEFAULT_MODE

Properties

$mode

$mode : string

Type

string

$success

$success : boolean

Type

boolean

$successUrl

$successUrl : string

Type

string

$failureUrl

$failureUrl : string

Type

string

Methods

__construct()

__construct(array|\ArrayAccess  $data = null) 

Parameters

array|\ArrayAccess $data

The dependencies (app and logger).

init()

init(\Psr\Http\Message\RequestInterface  $request) : boolean

Initialize the action with a request.

Parameters

\Psr\Http\Message\RequestInterface $request

The request to initialize.

Returns

boolean —

Success / Failure.

setDependencies()

setDependencies(\Pimple\Container  $container) : void

Give an opportunity to children classes to inject dependencies from a Pimple Container.

Does nothing by default, reimplement in children classes.

The $container DI-container (from Pimple) should not be saved or passed around, only to be used to inject dependencies (typically via setters).

Parameters

\Pimple\Container $container

A dependencies container instance.

__invoke()

__invoke(\Psr\Http\Message\RequestInterface  $request, \Psr\Http\Message\ResponseInterface  $response) : \Psr\Http\Message\ResponseInterface

Parameters

\Psr\Http\Message\RequestInterface $request

A PSR-7 compatible Request instance.

\Psr\Http\Message\ResponseInterface $response

A PSR-7 compatible Response instance.

Returns

\Psr\Http\Message\ResponseInterface

setMode()

setMode(string  $mode) : \Charcoal\App\Action\ActionInterface

Parameters

string $mode

The action mode.

Throws

\InvalidArgumentException

If the mode argument is not a string.

Returns

\Charcoal\App\Action\ActionInterface

Chainable

mode()

mode() : string

Returns

string

setSuccess()

setSuccess(boolean  $success) : \Charcoal\App\Action\ActionInterface

Parameters

boolean $success

Success flag (true / false).

Throws

\InvalidArgumentException

If the success argument is not a boolean.

Returns

\Charcoal\App\Action\ActionInterface

Chainable

success()

success() : boolean

Returns

boolean

setSuccessUrl()

setSuccessUrl(string|null  $url) : \Charcoal\App\Action\ActionInterface

Parameters

string|null $url

The success URL.

Throws

\InvalidArgumentException

If the URL parameter is not a string.

Returns

\Charcoal\App\Action\ActionInterface

Chainable

successUrl()

successUrl() : string

Returns

string

setFailureUrl()

setFailureUrl(string|null  $url) : \Charcoal\App\Action\ActionInterface

Parameters

string|null $url

The success URL.

Throws

\InvalidArgumentException

If the URL parameter is not a string.

Returns

\Charcoal\App\Action\ActionInterface

Chainable

failureUrl()

failureUrl() : string

Returns

string

redirectUrl()

redirectUrl() : string

Returns

string

results()

results() : array

Returns an associative array of results (set after being invoked / run).

The raw array of results will be called from __invoke().

Returns

array

run()

run(\Psr\Http\Message\RequestInterface  $request, \Psr\Http\Message\ResponseInterface  $response) : \Psr\Http\Message\ResponseInterface

Gets a psr7 request and response and returns a response.

Called from __invoke() as the first thing.

Parameters

\Psr\Http\Message\RequestInterface $request

A PSR-7 compatible Request instance.

\Psr\Http\Message\ResponseInterface $response

A PSR-7 compatible Response instance.

Returns

\Psr\Http\Message\ResponseInterface