1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Silverback API Components Bundle Project |
5
|
|
|
* |
6
|
|
|
* (c) Daniel West <[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 Silverback\ApiComponentsBundle\Entity\Component; |
15
|
|
|
|
16
|
|
|
use ApiPlatform\Core\Annotation\ApiProperty; |
17
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
18
|
|
|
use Doctrine\ORM\Mapping as ORM; |
19
|
|
|
use Silverback\ApiComponentsBundle\Entity\Core\AbstractComponent; |
20
|
|
|
use Silverback\ApiComponentsBundle\Validator\Constraints as AcbAssert; |
21
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
22
|
|
|
use Traversable; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Daniel West <[email protected]> |
26
|
|
|
* |
27
|
|
|
* @ORM\Entity |
28
|
|
|
*/ |
29
|
|
|
class Collection extends AbstractComponent |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @ORM\Column(nullable=false) |
33
|
|
|
* @Assert\NotNull(message="The resource iri for a collection component is required") |
34
|
|
|
* @AcbAssert\ResourceIri() |
35
|
|
|
*/ |
36
|
|
|
private string $resourceIri; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @ORM\Column(type="integer", nullable=true) |
40
|
|
|
*/ |
41
|
|
|
private ?int $perPage; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @ORM\Column(type="json", nullable=true) |
45
|
|
|
*/ |
46
|
|
|
private ?array $defaultQueryParameters; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @ApiProperty(writable=false) |
50
|
|
|
*/ |
51
|
|
|
private array $collection = []; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @ApiProperty(writable=false) |
55
|
|
|
*/ |
56
|
|
|
private ?ArrayCollection $endpoints = null; |
57
|
|
|
|
58
|
|
|
public function getResourceIri(): string |
59
|
|
|
{ |
60
|
|
|
return $this->resourceIri; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function setResourceIri(string $resourceIri): self |
64
|
|
|
{ |
65
|
|
|
$this->resourceIri = $resourceIri; |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getPerPage(): ?int |
71
|
|
|
{ |
72
|
|
|
return $this->perPage; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function setPerPage(?int $perPage): self |
76
|
|
|
{ |
77
|
|
|
$this->perPage = $perPage; |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getDefaultQueryParameters(): ?array |
83
|
|
|
{ |
84
|
|
|
return $this->defaultQueryParameters; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function setDefaultQueryParameters(?array $defaultQueryParameters): self |
88
|
|
|
{ |
89
|
|
|
$this->defaultQueryParameters = $defaultQueryParameters; |
90
|
|
|
|
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function getCollection() |
95
|
|
|
{ |
96
|
|
|
return $this->collection; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function setCollection($collection): self |
100
|
|
|
{ |
101
|
|
|
if (!$collection instanceof Traversable && !\is_array($collection)) { |
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
$this->collection = $collection; |
105
|
|
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getEndpoints(): ?ArrayCollection |
110
|
|
|
{ |
111
|
|
|
return $this->endpoints; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function setEndpoints(ArrayCollection $endpoints): self |
115
|
|
|
{ |
116
|
|
|
$this->endpoints = $endpoints; |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function addEndpoint(string $method, string $route): self |
122
|
|
|
{ |
123
|
|
|
if (!$this->endpoints) { |
124
|
|
|
$this->endpoints = new ArrayCollection(); |
125
|
|
|
} |
126
|
|
|
$this->endpoints->set($method, $route); |
127
|
|
|
|
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|