1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\Entity\Content; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\Common\Collections\Collection; |
7
|
|
|
use Doctrine\ORM\Mapping as ORM; |
8
|
|
|
use Ramsey\Uuid\Uuid; |
9
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\Component\ComponentLocation; |
10
|
|
|
use Silverback\ApiComponentBundle\Entity\Route\RouteAwareTrait; |
11
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
12
|
|
|
use Symfony\Component\Serializer\Annotation\MaxDepth; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class AbstractContent |
16
|
|
|
* @package Silverback\ApiComponentBundle\Entity |
17
|
|
|
* @author Daniel West <[email protected]> |
18
|
|
|
* @ORM\Entity() |
19
|
|
|
* @ORM\Table(name="route_content") |
20
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE") |
21
|
|
|
* @ORM\DiscriminatorColumn(name="type", type="string") |
22
|
|
|
* @ORM\DiscriminatorMap({ |
23
|
|
|
* "page" = "Silverback\ApiComponentBundle\Entity\Content\Page", |
24
|
|
|
* "component_group" = "Silverback\ApiComponentBundle\Entity\Content\ComponentGroup" |
25
|
|
|
* }) |
26
|
|
|
*/ |
27
|
|
|
abstract class AbstractContent implements ContentInterface |
28
|
|
|
{ |
29
|
|
|
use RouteAwareTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @ORM\Id() |
33
|
|
|
* @ORM\Column(type="string") |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $id; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @ORM\OneToMany(targetEntity="Silverback\ApiComponentBundle\Entity\Content\Component\ComponentLocation", mappedBy="content", cascade={"persist", "remove"}) |
40
|
|
|
* @Groups({"content", "route"}) |
41
|
|
|
* @MaxDepth(10) |
42
|
|
|
* @var Collection|ComponentLocation[] |
43
|
|
|
*/ |
44
|
|
|
protected $components; |
45
|
|
|
|
46
|
24 |
|
public function __construct() |
47
|
|
|
{ |
48
|
24 |
|
$this->routes = new ArrayCollection; |
49
|
24 |
|
$this->id = Uuid::uuid4()->getHex(); |
50
|
24 |
|
$this->components = new ArrayCollection; |
51
|
24 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function getId(): string |
57
|
|
|
{ |
58
|
|
|
return $this->id; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return Collection|ComponentLocation[] |
63
|
|
|
*/ |
64
|
2 |
|
public function getComponents(): Collection |
65
|
|
|
{ |
66
|
2 |
|
return $this->components; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param ComponentLocation $component |
71
|
|
|
* @return AbstractContent |
72
|
|
|
*/ |
73
|
1 |
|
public function addComponent(ComponentLocation $component): AbstractContent |
74
|
|
|
{ |
75
|
1 |
|
$this->components->add($component); |
76
|
1 |
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param ComponentLocation $component |
81
|
|
|
* @return AbstractContent |
82
|
|
|
*/ |
83
|
|
|
public function removeComponent(ComponentLocation $component): AbstractContent |
84
|
|
|
{ |
85
|
|
|
$this->components->removeElement($component); |
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|