Base resource class

Essentially, simply marshalls arguments and triggers events; it is useless without listeners to do the actual work.

 Methods

Create a record in the resource

create(array | object $data) : array | object

Expects either an array or object representing the item to create. If a non-array, non-object is provided, raises an exception.

The value returned by the last listener to the "create" event will be returned as long as it is an array or object; otherwise, the original $data is returned. If you wish to indicate failure to create, raise a PhlyRestfully\Exception\CreationException from a listener.

Parameters

$data

arrayobject

Exceptions

\PhlyRestfully\Exception\InvalidArgumentException

Returns

arrayobject

Delete an existing item

delete(string | int $id) : bool

Use to delete the item indicated by $id. The value returned by the last listener will be used, as long as it is a boolean; otherwise, a boolean false will be returned, indicating failure to delete.

Parameters

$id

stringint

Returns

bool

Delete an existing collection of records

deleteList(null | array $data) : bool

Parameters

$data

nullarray

Returns

bool

Fetch an existing item

fetch(string | int $id) : false | array | object

Retrieve an existing item indicated by $id. The value of the last listener will be returned, as long as it is an array or object; otherwise, a boolean false value will be returned, indicating a lookup failure.

Parameters

$id

stringint

Returns

falsearrayobject

Fetch a collection of items

fetchAll() : array | \Traversable

Use to retrieve a collection of items. The value of the last listener will be returned, as long as it is an array or Traversable; otherwise, an empty array will be returned.

The recommendation is to return a \Zend\Paginator\Paginator instance, which will allow performing paginated sets, and thus allow the view layer to select the current page based on the query string or route.

Returns

array\Traversable

Retrieve event manager

getEventManager() : \Zend\EventManager\EventManagerInterface

Lazy-instantiates an EM instance if none provided.

Returns

\Zend\EventManager\EventManagerInterface

getEventParam()

getEventParam(mixed $name, mixed $default) : mixed

Parameters

$name

mixed

$default

mixed

Returns

mixed

Get the event parameters

getEventParams() : array

Returns

array

getQueryParams()

getQueryParams() : null | \Zend\Stdlib\Parameters

Returns

null\Zend\Stdlib\Parameters

getRouteMatch()

getRouteMatch() : null | \Zend\Mvc\Router\RouteMatch

Returns

null\Zend\Mvc\Router\RouteMatch

Partial update of an existing item

patch(string | int $id, array | object $data) : array | object

Update the item indicated by $id, using the information from $data; $data should be merged with the existing item in order to provide a partial update. Additionally, $data should be an array or object; any other value will raise an exception.

Like create(), the return value of the last executed listener will be returned, as long as it is an array or object; otherwise, $data is returned. If you wish to indicate failure to update, raise a PhlyRestfully\Exception\PatchException.

Parameters

$id

stringint

$data

arrayobject

Exceptions

\PhlyRestfully\Exception\InvalidArgumentException

Returns

arrayobject

Update (replace) an existing collection of items

replaceList(array $data) : array | object

Replaces the collection with the items contained in $data. $data should be a multidimensional array or array of objects; if otherwise, an exception will be raised.

Like update(), the return value of the last executed listener will be returned, as long as it is an array or object; otherwise, $data is returned. If you wish to indicate failure to update, raise a PhlyRestfully\Exception\UpdateException.

Parameters

$data

array

Exceptions

\PhlyRestfully\Exception\InvalidArgumentException

Returns

arrayobject

Set event manager instance

setEventManager(\Zend\EventManager\EventManagerInterface $events) : Resource

Sets the event manager identifiers to the current class, this class, and the resource interface.

Parameters

$events

\Zend\EventManager\EventManagerInterface

Returns

Resource

setEventParam()

setEventParam(string $name, mixed $value) : mixed

Parameters

$name

string

$value

mixed

Returns

mixed

Set the event parameters

setEventParams(array $params) : \PhlyRestfully\Resource
fluent This method is part of a fluent interface and will return the same instance

Parameters

$params

array

Returns

setQueryParams()

setQueryParams(\Zend\Stdlib\Parameters $params) : \PhlyRestfully\Resource
fluent This method is part of a fluent interface and will return the same instance

Parameters

$params

\Zend\Stdlib\Parameters

Returns

setRouteMatch()

setRouteMatch(\Zend\Mvc\Router\RouteMatch $matches) : \PhlyRestfully\Resource
fluent This method is part of a fluent interface and will return the same instance

Parameters

$matches

\Zend\Mvc\Router\RouteMatch

Returns

Update (replace) an existing item

update(string | int $id, array | object $data) : array | object

Updates the item indicated by $id, replacing it with the information in $data. $data should be a full representation of the item, and should be an array or object; if otherwise, an exception will be raised.

Like create(), the return value of the last executed listener will be returned, as long as it is an array or object; otherwise, $data is returned. If you wish to indicate failure to update, raise a PhlyRestfully\Exception\UpdateException.

Parameters

$id

stringint

$data

arrayobject

Exceptions

\PhlyRestfully\Exception\InvalidArgumentException

Returns

arrayobject