klimesf/nette-hateoas

Hateoas integration into Nette Framework.

This package's canonical repository appears to be gone and the package has been frozen as a result.

v0.5.0 2015-09-23 11:39 UTC

This package is not auto-updated.

Last update: 2021-12-11 02:51:21 UTC


README

Build Status Latest Stable Version

Hateoas integration into Nette Framework.

For documentation, please refer to Hateoas GitHub or to Official Hateoas webpage.

Requirements

Hateoas requires

Installation

Install Hateoas via Composer.

composer require klimesf/nette-hateoas

Configuration

services:
	myUrlGenerator: App\My\DefaultUrlGenerator
	myOtherUrlGenerator: App\My\OtherUrlGenerator

extensions:
	hateoas: Klimesf\Hateoas\DI\HateoasExtension
	
hateoas:
	cacheDir: %tempDir%/cache/hateoas
	debugMode: %debugMode%
	jsonSerializer: App\My\JsonSerializer
	xmlSerializer: App\My\XmlSerializer
	urlGenerators:
		- App\My\DefaultUrlGenerator
		other: App\My\OtherUrlGenerator
	expressionContextVariables:
		foo: "value"
		bar: "value"
	expressionLanguage: App\My\ExpressionLanguage
	expressionFunctions:
		- App\My\ExpressionFunction
		- App\My\OtherExpressionFunction
	relationProviderResolvers:
		- App\My\RelationProviderResolver
		- App\My\OtherRelationProviderResolver

All the Url generators must be registered as services.

Usage

Require Hateoas\Hateoas class and send the json.

class MyPresenter extends Nette\Application\UI\Presenter
{

	/** @var Hateoas\Hateoas @inject */
	public $hateoas;
	
	public function actionDefault()
	{
		$entity = // ...
		$json = $this->hateoas->serialize($entity, 'json');
		$this->sendResponse(new Klimesf\Hateoas\HalJsonResponse($json)); // Sends HAL JSON response
	}

}