1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the API Platform project. |
5
|
|
|
* |
6
|
|
|
* (c) Kévin Dunglas <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace ApiPlatform\Core\Metadata\Property; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Subresource metadata. |
18
|
|
|
* |
19
|
|
|
* @author Antoine Bluchet <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
final class SubresourceMetadata |
22
|
|
|
{ |
23
|
|
|
private $resourceClass; |
24
|
|
|
private $collection; |
25
|
|
|
private $maxDepth; |
26
|
|
|
private $postEnabled; |
27
|
|
|
private $deleteEnabled; |
28
|
|
|
|
29
|
|
|
public function __construct(string $resourceClass, bool $collection = false, int $maxDepth = null, bool $postEnabled = true, bool $deleteEnabled = true) |
30
|
|
|
{ |
31
|
|
|
$this->resourceClass = $resourceClass; |
32
|
|
|
$this->collection = $collection; |
33
|
|
|
$this->maxDepth = $maxDepth; |
34
|
|
|
$this->postEnabled = $postEnabled; |
35
|
|
|
$this->deleteEnabled = $deleteEnabled; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getResourceClass(): string |
39
|
|
|
{ |
40
|
|
|
return $this->resourceClass; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function withResourceClass($resourceClass): self |
44
|
|
|
{ |
45
|
|
|
$metadata = clone $this; |
46
|
|
|
$metadata->resourceClass = $resourceClass; |
47
|
|
|
|
48
|
|
|
return $metadata; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function isCollection(): bool |
52
|
|
|
{ |
53
|
|
|
return $this->collection; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function withCollection(bool $collection): self |
57
|
|
|
{ |
58
|
|
|
$metadata = clone $this; |
59
|
|
|
$metadata->collection = $collection; |
60
|
|
|
|
61
|
|
|
return $metadata; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getMaxDepth(): ?int |
65
|
|
|
{ |
66
|
|
|
return $this->maxDepth; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function isPostEnabled(): bool |
70
|
|
|
{ |
71
|
|
|
return $this->postEnabled; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function isDeleteEnabled(): bool |
75
|
|
|
{ |
76
|
|
|
return $this->deleteEnabled; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|