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\Dto; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
17
|
|
|
use Silverback\ApiComponentBundle\Entity\Component\Collection as CollectionResource; |
18
|
|
|
use Symfony\Component\Serializer\Annotation\SerializedName; |
19
|
|
|
use Traversable; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Daniel West <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class Collection |
25
|
|
|
{ |
26
|
|
|
private CollectionResource $resource; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @SerializedName("collection") |
30
|
|
|
* |
31
|
|
|
* @var array|Traversable |
32
|
|
|
*/ |
33
|
|
|
private $collection; |
34
|
|
|
|
35
|
|
|
private ?ArrayCollection $endpoints = null; |
36
|
|
|
|
37
|
|
|
public function __construct(CollectionResource $parentObj) |
38
|
|
|
{ |
39
|
|
|
$this->resource = $parentObj; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getResource(): CollectionResource |
43
|
|
|
{ |
44
|
|
|
return $this->resource; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getCollection() |
48
|
|
|
{ |
49
|
|
|
return $this->collection; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function setCollection($collection): self |
53
|
|
|
{ |
54
|
|
|
if (!$collection instanceof Traversable && !\is_array($collection)) { |
55
|
|
|
return $this; |
56
|
|
|
} |
57
|
|
|
$this->collection = $collection; |
58
|
|
|
|
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getEndpoints(): ?ArrayCollection |
63
|
|
|
{ |
64
|
|
|
return $this->endpoints; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function setEndpoints(ArrayCollection $endpoints): self |
68
|
|
|
{ |
69
|
|
|
$this->endpoints = $endpoints; |
70
|
|
|
|
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function addEndpoint(string $method, string $route): self |
75
|
|
|
{ |
76
|
|
|
if (!$this->endpoints) { |
77
|
|
|
$this->endpoints = new ArrayCollection(); |
78
|
|
|
} |
79
|
|
|
$this->endpoints->set($method, $route); |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|