| @@ 35-87 (lines=53) @@ | ||
| 32 | }; | |
| 33 | use Symfony\Component\HttpFoundation\Request; | |
| 34 | ||
| 35 | final class LinkController | |
| 36 | { | |
| 37 | private $gateways; | |
| 38 | private $headerBuilder; | |
| 39 | private $translator; | |
| 40 | ||
| 41 | public function __construct( | |
| 42 | MapInterface $gateways, | |
| 43 | LinkBuilderInterface $headerBuilder, | |
| 44 | LinkTranslator $translator | |
| 45 |     ) { | |
| 46 | if ( | |
| 47 | (string) $gateways->keyType() !== 'string' || | |
| 48 | (string) $gateways->valueType() !== GatewayInterface::class | |
| 49 |         ) { | |
| 50 | throw new InvalidArgumentException; | |
| 51 | } | |
| 52 | ||
| 53 | $this->gateways = $gateways; | |
| 54 | $this->headerBuilder = $headerBuilder; | |
| 55 | $this->translator = $translator; | |
| 56 | } | |
| 57 | ||
| 58 | public function defaultAction(Request $request, $identity): ResponseInterface | |
| 59 |     { | |
| 60 |         $from = $request->attributes->get('_innmind_resource_definition'); | |
| 61 |         $request = $request->attributes->get('_innmind_request'); | |
| 62 |         $tos = $this->translator->translate($request->headers()->get('Link')); | |
| 63 | ||
| 64 | $linker = $this | |
| 65 | ->gateways | |
| 66 | ->get((string) $from->gateway()) | |
| 67 | ->resourceLinker(); | |
| 68 | $linker( | |
| 69 | $from = new Reference($from, new Identity($identity)), | |
| 70 | $tos | |
| 71 | ); | |
| 72 | ||
| 73 | return new Response( | |
| 74 |             $code = new StatusCode(StatusCode::codes()->get('NO_CONTENT')), | |
| 75 | new ReasonPhrase(ReasonPhrase::defaults()->get($code->value())), | |
| 76 | $request->protocolVersion(), | |
| 77 | new Headers( | |
| 78 | $this->headerBuilder->build( | |
| 79 | $request, | |
| 80 | $from, | |
| 81 | $tos | |
| 82 | ) | |
| 83 | ), | |
| 84 |             new StringStream('') | |
| 85 | ); | |
| 86 | } | |
| 87 | } | |
| 88 | ||
| @@ 35-87 (lines=53) @@ | ||
| 32 | }; | |
| 33 | use Symfony\Component\HttpFoundation\Request; | |
| 34 | ||
| 35 | final class UnlinkController | |
| 36 | { | |
| 37 | private $gateways; | |
| 38 | private $headerBuilder; | |
| 39 | private $translator; | |
| 40 | ||
| 41 | public function __construct( | |
| 42 | MapInterface $gateways, | |
| 43 | UnlinkBuilderInterface $headerBuilder, | |
| 44 | LinkTranslator $translator | |
| 45 |     ) { | |
| 46 | if ( | |
| 47 | (string) $gateways->keyType() !== 'string' || | |
| 48 | (string) $gateways->valueType() !== GatewayInterface::class | |
| 49 |         ) { | |
| 50 | throw new InvalidArgumentException; | |
| 51 | } | |
| 52 | ||
| 53 | $this->gateways = $gateways; | |
| 54 | $this->headerBuilder = $headerBuilder; | |
| 55 | $this->translator = $translator; | |
| 56 | } | |
| 57 | ||
| 58 | public function defaultAction(Request $request, $identity): ResponseInterface | |
| 59 |     { | |
| 60 |         $from = $request->attributes->get('_innmind_resource_definition'); | |
| 61 |         $request = $request->attributes->get('_innmind_request'); | |
| 62 |         $tos = $this->translator->translate($request->headers()->get('Link')); | |
| 63 | ||
| 64 | $unlinker = $this | |
| 65 | ->gateways | |
| 66 | ->get((string) $from->gateway()) | |
| 67 | ->resourceUnlinker(); | |
| 68 | $unlinker( | |
| 69 | $from = new Reference($from, new Identity($identity)), | |
| 70 | $tos | |
| 71 | ); | |
| 72 | ||
| 73 | return new Response( | |
| 74 |             $code = new StatusCode(StatusCode::codes()->get('NO_CONTENT')), | |
| 75 | new ReasonPhrase(ReasonPhrase::defaults()->get($code->value())), | |
| 76 | $request->protocolVersion(), | |
| 77 | new Headers( | |
| 78 | $this->headerBuilder->build( | |
| 79 | $request, | |
| 80 | $from, | |
| 81 | $tos | |
| 82 | ) | |
| 83 | ), | |
| 84 |             new StringStream('') | |
| 85 | ); | |
| 86 | } | |
| 87 | } | |
| 88 | ||