1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\Rest\ServerBundle\Controller\Resource; |
5
|
|
|
|
6
|
|
|
use Innmind\Rest\ServerBundle\Exception\InvalidArgumentException; |
7
|
|
|
use Innmind\Rest\Server\{ |
8
|
|
|
Response\HeaderBuilder\RemoveBuilderInterface, |
9
|
|
|
GatewayInterface, |
10
|
|
|
Identity |
11
|
|
|
}; |
12
|
|
|
use Innmind\Http\{ |
13
|
|
|
Message\ResponseInterface, |
14
|
|
|
Message\Response, |
15
|
|
|
Message\StatusCode, |
16
|
|
|
Message\ReasonPhrase, |
17
|
|
|
Headers |
18
|
|
|
}; |
19
|
|
|
use Innmind\Filesystem\Stream\StringStream; |
20
|
|
|
use Innmind\Immutable\MapInterface; |
21
|
|
|
use Symfony\Component\HttpFoundation\Request; |
22
|
|
|
|
23
|
|
|
final class RemoveController |
24
|
|
|
{ |
25
|
|
|
private $gateways; |
26
|
|
|
private $headerBuilder; |
27
|
|
|
|
28
|
1 |
|
public function __construct( |
29
|
|
|
MapInterface $gateways, |
30
|
|
|
RemoveBuilderInterface $headerBuilder |
31
|
|
|
) { |
32
|
|
|
if ( |
33
|
1 |
|
(string) $gateways->keyType() !== 'string' || |
34
|
1 |
|
(string) $gateways->valueType() !== GatewayInterface::class |
35
|
|
|
) { |
36
|
|
|
throw new InvalidArgumentException; |
37
|
|
|
} |
38
|
|
|
|
39
|
1 |
|
$this->gateways = $gateways; |
40
|
1 |
|
$this->headerBuilder = $headerBuilder; |
41
|
1 |
|
} |
42
|
|
|
|
43
|
1 |
|
public function defaultAction(Request $request, $identity): ResponseInterface |
44
|
|
|
{ |
45
|
1 |
|
$definition = $request->attributes->get('_innmind_resource_definition'); |
46
|
1 |
|
$request = $request->attributes->get('_innmind_request'); |
47
|
|
|
|
48
|
|
|
$remover = $this |
49
|
1 |
|
->gateways |
50
|
1 |
|
->get((string) $definition->gateway()) |
51
|
1 |
|
->resourceRemover(); |
52
|
1 |
|
$remover( |
53
|
|
|
$definition, |
54
|
1 |
|
$identity = new Identity($identity) |
55
|
|
|
); |
56
|
|
|
|
57
|
1 |
|
return new Response( |
58
|
1 |
|
$code = new StatusCode(StatusCode::codes()->get('NO_CONTENT')), |
59
|
1 |
|
new ReasonPhrase(ReasonPhrase::defaults()->get($code->value())), |
60
|
1 |
|
$request->protocolVersion(), |
61
|
1 |
|
new Headers( |
62
|
1 |
|
$this->headerBuilder->build( |
63
|
|
|
$request, |
64
|
|
|
$definition, |
65
|
|
|
$identity |
66
|
|
|
) |
67
|
|
|
), |
68
|
1 |
|
new StringStream('') |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|