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