polidog / hypermedia-bundle
Support Hal
dev-master
2020-02-16 11:53 UTC
Requires
- php: ^7.1
- ext-json: *
- doctrine/common: ^2.6
- polidog/simple-api-bundle: ^0.0.7
- symfony/config: ^3.4|^4.4
- symfony/dependency-injection: ^3.4|^4.4
- symfony/event-dispatcher: ^3.4|^4.4
- symfony/http-foundation: ^3.4|^4.4
- symfony/http-kernel: ^3.4|^4.4
- symfony/routing: ^3.4|^4.4
This package is auto-updated.
Last update: 2024-11-16 22:27:25 UTC
README
HypermediaAPI bundle. This bundle support only HAL json. And you mast need polidog/simple-api-bundle
Installation
$ composer require polidog/hypermedia-bundle "dev-master"
<?php return [ ... Polidog\SimpleApiBundle\PolidogSimpleApiBundle::class => ['all' => true], Polidog\HypermediaBundle\HypermediaBundle::class => ['all' => true] ];
Introduce bundle configuration to your config file
# config/packages/polidog_hypermedia.yml polidog_hypermedia: ~ hal_content_type: false # default false
If hal_content_type
is true that need request header for application/hal+json
.
Usage
<?php declare(strict_types=1); namespace App\Controller\Api\Projects; use App\Repository\ProjectRepository; use Polidog\HypermediaBundle\Annotations\Embed; use Polidog\HypermediaBundle\Annotations\Link; use Polidog\SimpleApiBundle\Annotations\Api; use Symfony\Component\Routing\Annotation\Route; /** * @Route("/projects/{code}/detail", requirements={"code"}) * @Api(statusCode=200) * * @Embed(rel="members", src="/api/projects/{code}/members") * * @Link(rel="projects", href="/projects") * @Link(rel="project-new", href="/projects/new") * */ class DetailController { /** * @var ProjectRepository */ private $repository; public function __construct(ProjectRepository $repository) { $this->repository = $repository; } /** * @return array<string,array|null> */ public function __invoke(string $code): array { $project = $this->repository->findProjectCode($code); return [ 'project' => null !== $project ? $project->export() : null, ]; } }