MODE_JSON
MODE_JSON
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:
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).
\Pimple\Container | $container | A dependencies container instance. |
__invoke(\Psr\Http\Message\RequestInterface $request, \Psr\Http\Message\ResponseInterface $response) : \Psr\Http\Message\ResponseInterface
\Psr\Http\Message\RequestInterface | $request | A PSR-7 compatible Request instance. |
\Psr\Http\Message\ResponseInterface | $response | A PSR-7 compatible Response instance. |
setMode(string $mode) : \Charcoal\App\Action\ActionInterface
string | $mode | The action mode. |
If the mode argument is not a string.
Chainable
setSuccess(boolean $success) : \Charcoal\App\Action\ActionInterface
boolean | $success | Success flag (true / false). |
If the success argument is not a boolean.
Chainable
setSuccessUrl(string|null $url) : \Charcoal\App\Action\ActionInterface
string|null | $url | The success URL. |
If the URL parameter is not a string.
Chainable
setFailureUrl(string|null $url) : \Charcoal\App\Action\ActionInterface
string|null | $url | The success URL. |
If the URL parameter is not a string.
Chainable
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.
\Psr\Http\Message\RequestInterface | $request | A PSR-7 compatible Request instance. |
\Psr\Http\Message\ResponseInterface | $response | A PSR-7 compatible Response instance. |