PHP code example of runner / fastd-fractal
1. Go to this page and download the library: Download runner/fastd-fractal library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
runner / fastd-fractal example snippets
namespace Transformer;
use Runner\FastdFractal\AbstractTransformer;
class AppTransformer extends AbstractTransformer
{
public function transform($app)
{
return [
'id' => $app->id,
'name' => $app->name,
];
}
}
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);
}
}