Overview

Namespaces

  • Charcoal
    • App
      • Action
      • Config
      • Handler
      • Middleware
      • Module
      • Route
      • Script
      • ServiceProvider
      • Template

Classes

  • AbstractAction

Interfaces

  • ActionInterface
  • Overview
  • Namespace
  • Class

Class AbstractAction

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:

Charcoal\Config\AbstractEntity
Extended by Charcoal\App\Action\AbstractAction implements Charcoal\App\Action\ActionInterface, Psr\Log\LoggerAwareInterface uses Psr\Log\LoggerAwareTrait (not available)
Abstract
Namespace: Charcoal\App\Action
Located at Charcoal/App/Action/AbstractAction.php
Methods summary
public
# __construct( array|ArrayAccess $data = null )

Parameters

$data
The dependencies (app and logger).
public boolean
# init( Psr\Http\Message\RequestInterface $request )

Initialize the action with a request.

Initialize the action with a request.

Parameters

$request
The request to initialize.

Returns

boolean
Success / Failure.

Implementation of

Charcoal\App\Action\ActionInterface::init()
public
# setDependencies( Pimple\Container $container )

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

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

$container
A dependencies container instance.

Implementation of

Charcoal\App\Action\ActionInterface::setDependencies()
final public Psr\Http\Message\ResponseInterface
# __invoke( Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response )

Parameters

$request
A PSR-7 compatible Request instance.
$response
A PSR-7 compatible Response instance.

Returns

Psr\Http\Message\ResponseInterface

See

Charcoal\App\Action\AbstractAction::run()

Implementation of

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

Parameters

$mode
The action mode.

Returns

Charcoal\App\Action\ActionInterface
Chainable

Throws

InvalidArgumentException
If the mode argument is not a string.

Implementation of

Charcoal\App\Action\ActionInterface::setMode()
public string
# mode( )

Returns

string

Implementation of

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

Parameters

$success
Success flag (true / false).

Returns

Charcoal\App\Action\ActionInterface
Chainable

Throws

InvalidArgumentException
If the success argument is not a boolean.

Implementation of

Charcoal\App\Action\ActionInterface::setSuccess()
public boolean
# success( )

Returns

boolean

Implementation of

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

Parameters

$url
The success URL.

Returns

Charcoal\App\Action\ActionInterface
Chainable

Throws

InvalidArgumentException
If the URL parameter is not a string.

Implementation of

Charcoal\App\Action\ActionInterface::setSuccessUrl()
public string
# successUrl( )

Returns

string

Implementation of

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

Parameters

$url
The success URL.

Returns

Charcoal\App\Action\ActionInterface
Chainable

Throws

InvalidArgumentException
If the URL parameter is not a string.

Implementation of

Charcoal\App\Action\ActionInterface::setFailureUrl()
public string
# failureUrl( )

Returns

string

Implementation of

Charcoal\App\Action\ActionInterface::failureUrl()
public string
# redirectUrl( )

Returns

string

Implementation of

Charcoal\App\Action\ActionInterface::redirectUrl()
abstract public array
# results( )

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

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

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

Returns

array

Implementation of

Charcoal\App\Action\ActionInterface::results()
abstract public Psr\Http\Message\ResponseInterface
# run( Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response )

Gets a psr7 request and response and returns a response.

Gets a psr7 request and response and returns a response.

Called from __invoke() as the first thing.

Parameters

$request
A PSR-7 compatible Request instance.
$response
A PSR-7 compatible Response instance.

Returns

Psr\Http\Message\ResponseInterface

Implementation of

Charcoal\App\Action\ActionInterface::run()
Methods inherited from Charcoal\App\Action\ActionInterface
setData()
Constants summary
string MODE_JSON
# 'json'
string MODE_XML
# 'xml'
string MODE_REDIRECT
# 'redirect'
string DEFAULT_MODE
# Charcoal\App\Action\AbstractAction::MODE_JSON
API documentation generated by ApiGen