Abstract RESTful controller

Convenience methods for pre-built plugins (@see __call):

package Default
inherited_from \Zend\Mvc\Controller\AbstractController

 Methods

Method overloading: return/call plugins

__call(string $method, array $params) : mixed
Inherited

If the plugin is a functor, call it, passing the parameters provided. Otherwise, return the plugin instance.

Parameters

$method

string

$params

array

Returns

mixed

Register a handler for a custom HTTP method

addHttpMethodHandler(string $method, Callable $handler) : \Zend\Mvc\Controller\AbstractRestfulController

This method allows you to handle arbitrary HTTP method types, mapping them to callables. Typically, these will be methods of the controller instance: e.g., array($this, 'foobar'). The typical place to register these is in your constructor.

Additionally, as this map is checked prior to testing the standard HTTP methods, this is a way to override what methods will handle the standard HTTP methods. However, if you do this, you will have to retrieve the identifier and any request content manually.

Callbacks will be passed the current MvcEvent instance.

To retrieve the identifier, you can use "$id = $this->getIdentifier($routeMatch, $request)", passing the appropriate objects.

To retrieve the body content data, use "$data = $this->processBodyContent($request)"; that method will return a string, array, or, in the case of JSON, an object.

Parameters

$method

string

$handler

Callable

Returns

\Zend\Mvc\Controller\AbstractRestfulController

Create a new resource

create(mixed $data) : mixed

Parameters

$data

mixed

Returns

mixed

Delete an existing resource

delete(mixed $id) : mixed

Parameters

$id

mixed

Returns

mixed

Delete the entire resource collection

deleteList($data) : mixed

Not marked as abstract, as that would introduce a BC break (introduced in 2.1.0); instead, raises an exception if not implemented.

Parameters

$data

Returns

mixed

Dispatch a request

dispatch(\Zend\Stdlib\RequestInterface $request, null|\Zend\Stdlib\ResponseInterface $response = null) : mixed | \Zend\Stdlib\ResponseInterface

If the route match includes an "action" key, then this acts basically like a standard action controller. Otherwise, it introspects the HTTP method to determine how to handle the request, and which method to delegate to.

events dispatch.pre, dispatch.post
inherited_from \Zend\Mvc\Controller\AbstractController::dispatch()

Parameters

$request

\Zend\Stdlib\RequestInterface

$response

null\Zend\Stdlib\ResponseInterface

Exceptions

\Zend\Mvc\Exception\InvalidArgumentException

Returns

mixed\Zend\Stdlib\ResponseInterface

Dispatch a request

dispatch(\Zend\Stdlib\RequestInterface $request, null|\Zend\Stdlib\ResponseInterface $response = null) : \Zend\Stdlib\ResponseInterface | mixed
Inherited
events dispatch.pre, dispatch.post
inherited_from \Zend\Stdlib\DispatchableInterface::dispatch()

Parameters

$request

\Zend\Stdlib\RequestInterface

$response

null\Zend\Stdlib\ResponseInterface

Returns

\Zend\Stdlib\ResponseInterfacemixed

Return single resource

get(mixed $id) : mixed

Parameters

$id

mixed

Returns

mixed

Get the attached event

getEvent() : \Zend\Mvc\MvcEvent
Inherited

Will create a new MvcEvent if none provided.

inherited_from \Zend\Mvc\InjectApplicationEventInterface::getEvent()

Returns

\Zend\Mvc\MvcEvent

Retrieve the event manager

getEventManager() : \Zend\EventManager\EventManagerInterface
Inherited

Lazy-loads an EventManager instance if none registered.

Returns

\Zend\EventManager\EventManagerInterface

Retrieve the route match/query parameter name containing the identifier

getIdentifierName() : string

Returns

string

Return list of resources

getList() : mixed

Returns

mixed

Transform an "action" token into a method name

getMethodFromAction(string $action) : string
InheritedStatic

Parameters

$action

string

Returns

string

Get plugin manager

getPluginManager() : \Zend\Mvc\Controller\PluginManager
Inherited

Returns

\Zend\Mvc\Controller\PluginManager

Get request object

getRequest() : \Zend\Stdlib\RequestInterface
Inherited

Returns

\Zend\Stdlib\RequestInterface

Get response object

getResponse() : \Zend\Stdlib\ResponseInterface
Inherited

Returns

\Zend\Stdlib\ResponseInterface

Retrieve serviceManager instance

getServiceLocator() : \Zend\ServiceManager\ServiceLocatorInterface
Inherited
inherited_from \Zend\ServiceManager\ServiceLocatorAwareInterface::getServiceLocator()

Returns

\Zend\ServiceManager\ServiceLocatorInterface

Retrieve HEAD metadata for the resource

head(null|mixed $id = null) : mixed

Not marked as abstract, as that would introduce a BC break (introduced in 2.1.0); instead, raises an exception if not implemented.

Parameters

$id

nullmixed

Returns

mixed

Basic functionality for when a page is not available

notFoundAction() : array

Returns

array

Handle the request

onDispatch(\Zend\Mvc\MvcEvent $e) : mixed
todo try-catch in "patch" for patchList should be removed in the future
inherited_from \Zend\Mvc\Controller\AbstractController::onDispatch()

Parameters

$e

\Zend\Mvc\MvcEvent

Exceptions

\Zend\Mvc\Exception\DomainException if no route matches in event or invalid HTTP method

Returns

mixed

Execute the request

onDispatch(\Zend\Mvc\MvcEvent $e) : mixed
Inherited

Parameters

$e

\Zend\Mvc\MvcEvent

Returns

mixed

Respond to the OPTIONS method

options() : mixed

Typically, set the Allow header with allowed HTTP methods, and return the response.

Not marked as abstract, as that would introduce a BC break (introduced in 2.1.0); instead, raises an exception if not implemented.

Returns

mixed

Respond to the PATCH method

patch($id, $data) : array

Not marked as abstract, as that would introduce a BC break (introduced in 2.1.0); instead, raises an exception if not implemented.

Parameters

$id

$data

Returns

array

Modify a resource collection without completely replacing it

patchList(mixed $data) : mixed

Not marked as abstract, as that would introduce a BC break (introduced in 2.2.0); instead, raises an exception if not implemented.

Parameters

$data

mixed

Returns

mixed

Get plugin instance

plugin(string $name, null|array $options = null) : mixed
Inherited

Parameters

$name

string

Name of plugin to return

$options

nullarray

Options to pass to plugin constructor (if not already instantiated)

Returns

mixed

Process post data and call create

processPostData(\Zend\Stdlib\RequestInterface $request) : mixed

Parameters

$request

\Zend\Stdlib\RequestInterface

Returns

mixed

Replace an entire resource collection

replaceList(mixed $data) : mixed

Not marked as abstract, as that would introduce a BC break (introduced in 2.1.0); instead, raises an exception if not implemented.

Parameters

$data

mixed

Returns

mixed

Check if request has certain content type

requestHasContentType(\Zend\Stdlib\RequestInterface $request, string|null $contentType = '') : boolean

Parameters

$request

\Zend\Stdlib\RequestInterface

$contentType

stringnull

Returns

boolean

Set an event to use during dispatch

setEvent(\Zend\EventManager\EventInterface $e) : void
Inherited

By default, will re-cast to MvcEvent if another event type is provided.

inherited_from \Zend\Mvc\InjectApplicationEventInterface::setEvent()

Parameters

$e

\Zend\EventManager\EventInterface

Set the event manager instance used by this context

setEventManager(\Zend\EventManager\EventManagerInterface $events) : \Zend\Mvc\Controller\AbstractController
Inherited
inherited_from \Zend\EventManager\EventManagerAwareInterface::setEventManager()

Parameters

$events

\Zend\EventManager\EventManagerInterface

Returns

\Zend\Mvc\Controller\AbstractController

Set the route match/query parameter name containing the identifier

setIdentifierName(string $name) : \Zend\Mvc\Controller\AbstractRestfulController
fluent This method is part of a fluent interface and will return the same instance

Parameters

$name

string

Returns

\Zend\Mvc\Controller\AbstractRestfulController

Set plugin manager

setPluginManager(\Zend\Mvc\Controller\PluginManager $plugins) : \Zend\Mvc\Controller\AbstractController
Inherited

Parameters

$plugins

\Zend\Mvc\Controller\PluginManager

Returns

\Zend\Mvc\Controller\AbstractController

Set serviceManager instance

setServiceLocator(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) : void
Inherited
inherited_from \Zend\ServiceManager\ServiceLocatorAwareInterface::setServiceLocator()

Parameters

$serviceLocator

\Zend\ServiceManager\ServiceLocatorInterface

Update an existing resource

update(mixed $id, mixed $data) : mixed

Parameters

$id

mixed

$data

mixed

Returns

mixed

Register the default events for this controller

attachDefaultListeners() : void
Inherited

Retrieve the identifier, if any

getIdentifier(\Zend\Mvc\Router\RouteMatch $routeMatch, \Zend\Stdlib\RequestInterface $request) : false | mixed

Attempts to see if an identifier was passed in either the URI or the query string, returning it if found. Otherwise, returns a boolean false.

Parameters

$routeMatch

\Zend\Mvc\Router\RouteMatch

$request

\Zend\Stdlib\RequestInterface

Returns

falsemixed

Process the raw body content

processBodyContent(mixed $request) : object | string | array

If the content-type indicates a JSON payload, the payload is immediately decoded and the data returned. Otherwise, the data is passed to parse_str(). If that function returns a single-member array with a key of "0", the method assumes that we have non-urlencoded content and returns the raw content; otherwise, the array created is returned.

Parameters

$request

mixed

Returns

objectstringarray

 Properties

 

$contentTypes

$contentTypes : array

Default

array(self::CONTENT_TYPE_JSON => array('application/hal+json', 'application/json'))
 

Map of custom HTTP methods and their handlers

$customHttpMethodsMap : array

Default

array()
 

$event

$event : \Zend\EventManager\EventInterface

Default

 

$eventIdentifier

$eventIdentifier 

Default

__CLASS__
inherited_from \Zend\Mvc\Controller\AbstractController::eventIdentifier
 

$eventIdentifier

$eventIdentifier : null | string | array<mixed,string>

Default

 

$events

$events : \Zend\EventManager\EventManagerInterface

Default

 

Name of request or query parameter containing identifier

$identifierName : string

Default

'id'
 

From Zend\Json\Json

$jsonDecodeType : integer

Default

\Zend\Json\Json::TYPE_ARRAY
 

$plugins

$plugins : \Zend\Mvc\Controller\PluginManager

Default

 

$request

$request : \Zend\Stdlib\RequestInterface

Default

 

$response

$response : \Zend\Stdlib\ResponseInterface

Default

 

$serviceLocator

$serviceLocator : \Zend\ServiceManager\ServiceLocatorInterface

Default

 Constants

 

CONTENT_TYPE_JSON

CONTENT_TYPE_JSON = 'json'