runner / fastd-fractal
fractal for FastD framework
Installs: 3 842
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.1
- fastd/fastd: ~3.0
- illuminate/pagination: ^5.5
- league/fractal: ^0.17.0
Requires (Dev)
- phpunit/phpunit: ^5.0
This package is auto-updated.
Last update: 2020-01-28 13:17:52 UTC
README
Usage
首先定义 Tranformer
<?php namespace Transformer; use Runner\FastdFractal\AbstractTransformer; class AppTransformer extends AbstractTransformer { public function transform($app) { return [ 'id' => $app->id, 'name' => $app->name, ]; } }
<?php namespace Controller; use Models\App; use FastD\Http\ServerRequest; use Transformer\AppTransformer; use FastD\Http\Response; class AppsController { public function show(ServerRequest $request) { $app = App::find($request->getAttribute('id')); return fractal()->item($app, AppTransformer::class, Response::HTTP_OK); } }
请求后, 将输出
HTTP 200 OK
{"id": 1, "name": "testing"}