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\HalCollection` `array` `object`

#### $route

`null` `string`

### Returns

`\PhlyRestfully\HalCollection`

## createCollectionFromMetadata()

    createCollectionFromMetadata(object $object, \PhlyRestfully\Metadata $metadata) : \PhlyRestfully\HalCollection

### Parameters

#### $object

`object`

#### $metadata

`\PhlyRestfully\Metadata`

### Returns

`\PhlyRestfully\HalCollection`

## Create a fully qualified URI for a link

    createLink(string $route, null | false | int | string $id, null | mixed $resource) : string

Triggers the "createLink" event with the route, id, resource, and a set of params that will be passed to the route; listeners can alter any of the arguments, which will then be used by the method to generate the url.

### Parameters

#### $route

`string`

#### $id

`null` `false` `int` `string`

#### $resource

`null` `mixed`

### Returns

`string`

## 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\HalResource` `array` `object`

#### $route

`string`

#### $identifierName

`string`

### Returns

`\PhlyRestfully\HalResource`

## Create a resource and/or collection based on a metadata map

    createResourceFromMetadata(object $object, \PhlyRestfully\Metadata $metadata) : \PhlyRestfully\HalResource | \PhlyRestfully\HalCollection

### Parameters

#### $object

`object`

#### $metadata

`\PhlyRestfully\Metadata`

### Returns

`\PhlyRestfully\HalResource``\PhlyRestfully\HalCollection`

## Generate HAL links from a LinkCollection

    fromLinkCollection(\PhlyRestfully\LinkCollection $collection) : array

### Parameters

#### $collection

`\PhlyRestfully\LinkCollection`

### Returns

`array`

## Create HAL links "object" from a resource/collection

    fromResource(\PhlyRestfully\LinkCollectionAwareInterface $resource) : array

### Parameters

#### $resource

`\PhlyRestfully\LinkCollectionAwareInterface`

### 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\HydratorInterface` `false`

## Retrieve the metadata map

    getMetadataMap() : \PhlyRestfully\MetadataMap

### Returns

`\PhlyRestfully\MetadataMap`

## Inject a "self" relational link based on the route and identifier

    injectSelfLink(\PhlyRestfully\LinkCollectionAwareInterface $resource, string $route, string $identifier)

### Parameters

#### $resource

`\PhlyRestfully\LinkCollectionAwareInterface`

#### $route

`string`

#### $identifier

`string`

## "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

#### $halCollection

`\PhlyRestfully\HalCollection`

### Returns

`array``\PhlyRestfully\ApiProblem`Associative 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

#### $halResource

`\PhlyRestfully\HalResource`

### 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

#### $map

`\PhlyRestfully\MetadataMap`

### Returns

`\PhlyRestfully\Plugin\HalLinks`

## 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`