klimesf / nette-hateoas
Hateoas 集成到 Nette 框架中。
该软件包的官方仓库似乎已消失,因此该软件包已被冻结。
v0.5.0
2015-09-23 11:39 UTC
Requires
- php: >= 5.4
- nette/application: ^2.3
- nette/di: ^2.3
- willdurand/hateoas: ^2.8
Requires (Dev)
- nette/tester: ^1.5
- tracy/tracy: ^2.3
This package is not auto-updated.
Last update: 2021-12-11 02:51:21 UTC
README
Hateoas 集成到 Nette 框架中。
有关文档,请参阅 Hateoas GitHub 或 官方 Hateoas 网页。
需求
Hateoas 需要
安装
通过 Composer 安装 Hateoas。
composer require klimesf/nette-hateoas
配置
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
所有 URL 生成器都必须注册为服务。
使用方法
要求引入 Hateoas\Hateoas
类并发送 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 } }