Generate links for use with HAL payloads

 Methods

Map a resource class to a specific hydrator instance

addHydrator(string $class, \Zend\Stdlib\Hydrator\HydratorInterface $hydrator) : \PhlyRestfully\Plugin\RestfulJsonRenderer

Parameters

$class

string

$hydrator

\Zend\Stdlib\Hydrator\HydratorInterface

Returns

\PhlyRestfully\Plugin\RestfulJsonRenderer

Creates a HalCollection instance with a self relational link

createCollection(\PhlyRestfully\HalCollection | array | object $collection, null | string $route) : \PhlyRestfully\HalCollection

Parameters

$collection

\PhlyRestfully\HalCollectionarrayobject

$route

nullstring

Returns

Create a HalResource instance and inject it with a self relational link

createResource(\PhlyRestfully\HalResource | array | object $resource, string $route, string $identifierName) : \PhlyRestfully\HalResource

Parameters

$resource

\PhlyRestfully\HalResourcearrayobject

$route

string

$identifierName

string

Returns

Generate HAL links from a LinkCollection

fromLinkCollection(\PhlyRestfully\LinkCollection $collection) : array

Parameters

Returns

array

Create HAL links "object" from a resource/collection

fromResource(\PhlyRestfully\LinkCollectionAwareInterface $resource) : array

Parameters

Returns

array

getController()

getController() : \Zend\Stdlib\DispatchableInterface

Returns

\Zend\Stdlib\DispatchableInterface

Retrieve the event manager instance

getEventManager() : \Zend\EventManager\EventManagerInterface

Lazy-initializes one if none present.

Returns

\Zend\EventManager\EventManagerInterface

Retrieve a hydrator for a given resource

getHydratorForResource(object $resource) : \Zend\Stdlib\Hydrator\HydratorInterface | false

If the resource has a mapped hydrator, returns that hydrator. If not, and a default hydrator is present, the default hydrator is returned. Otherwise, a boolean false is returned.

Parameters

$resource

object

Returns

\Zend\Stdlib\Hydrator\HydratorInterfacefalse

Retrieve the metadata map

getMetadataMap() : \PhlyRestfully\MetadataMap

"Render" a HalCollection

renderCollection(\PhlyRestfully\HalCollection $halCollection) : array | \PhlyRestfully\ApiProblem

Injects pagination links, if the composed collection is a Paginator, and then loops through the collection to create the data structure representing the collection.

For each resource in the collection, the event "renderCollection.resource" is triggered, with the following parameters:

  • "collection", which is the $halCollection passed to the method
  • "resource", which is the current resource
  • "route", the resource route that will be used to generate links
  • "routeParams", any default routing parameters/substitutions to use in URL assembly
  • "routeOptions", any default routing options to use in URL assembly

This event can be useful particularly when you have multi-segment routes and wish to ensure that route parameters are injected, or if you want to inject query or fragment parameters.

Event parameters are aggregated in an ArrayObject, which allows you to directly manipulate them in your listeners:

$params = $e->getParams();
$params['routeOptions']['query'] = array('format' => 'json');

Parameters

Returns

array\PhlyRestfully\ApiProblemAssociative array representing the payload to render; returns ApiProblem if error in pagination occurs

Render an individual resource

renderResource(\PhlyRestfully\HalResource $halResource) : array

Creates a hash representation of the HalResource. The resource is first converted to an array, and its associated links are injected as the "_links" member. If any members of the resource are themselves HalResource objects, they are extracted into an "_embedded" hash.

Parameters

Returns

array

setController()

setController(\Zend\Stdlib\DispatchableInterface $controller) 

Parameters

$controller

\Zend\Stdlib\DispatchableInterface

Set the default hydrator to use if none specified for a class.

setDefaultHydrator(\Zend\Stdlib\Hydrator\HydratorInterface $hydrator) : \PhlyRestfully\Plugin\RestfulJsonRenderer

Parameters

$hydrator

\Zend\Stdlib\Hydrator\HydratorInterface

Returns

\PhlyRestfully\Plugin\RestfulJsonRenderer

Set the event manager instance

setEventManager(\Zend\EventManager\EventManagerInterface $events) 

Parameters

$events

\Zend\EventManager\EventManagerInterface

Set the metadata map

setMetadataMap(\PhlyRestfully\MetadataMap $map) : \PhlyRestfully\Plugin\HalLinks
fluent This method is part of a fluent interface and will return the same instance

Parameters

Returns

setServerUrlHelper()

setServerUrlHelper(\Zend\View\Helper\ServerUrl $helper) 

Parameters

$helper

\Zend\View\Helper\ServerUrl

setUrlHelper()

setUrlHelper(\Zend\View\Helper\Url $helper) 

Parameters

$helper

\Zend\View\Helper\Url