|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Silverback\ApiComponentBundle\Entity\Route; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\Collection; |
|
8
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
9
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\Page\Dynamic\DynamicContent; |
|
10
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\Page\StaticPage; |
|
11
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
|
12
|
|
|
|
|
13
|
|
|
trait RouteAwareTrait |
|
14
|
|
|
{ |
|
15
|
|
|
use ChildRouteTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @ORM\OneToMany(targetEntity="Silverback\ApiComponentBundle\Entity\Route\Route", mappedBy="staticPage", cascade={"persist"}) |
|
19
|
|
|
* @Groups({"default", "route_read"}) |
|
20
|
|
|
* @var Collection|Route[] |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $routes; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var bool |
|
26
|
|
|
* @Groups({"default_write"}) |
|
27
|
|
|
*/ |
|
28
|
|
|
private $regenerateRoute = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param Route $route |
|
32
|
|
|
* @return RouteAwareInterface|RouteAwareTrait |
|
33
|
|
|
*/ |
|
34
|
|
|
public function addRoute(Route $route) |
|
35
|
|
|
{ |
|
36
|
|
|
if ($this instanceof DynamicContent) { |
|
37
|
|
|
$route->setDynamicContent($this); |
|
38
|
|
|
} |
|
39
|
|
|
if ($this instanceof StaticPage) { |
|
40
|
|
|
$route->setStaticPage($this); |
|
41
|
|
|
} |
|
42
|
|
|
$this->routes->add($route); |
|
43
|
|
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param Route $route |
|
48
|
|
|
* @return RouteAwareInterface|RouteAwareTrait |
|
49
|
|
|
*/ |
|
50
|
|
|
public function removeRoute(Route $route) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->routes->removeElement($route); |
|
53
|
|
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return Collection|Route[] |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getRoutes(): Collection |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->routes; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function setRegenerateRoute(bool $regenerateRoute) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->regenerateRoute = $regenerateRoute; |
|
67
|
|
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getRegenerateRoute(): bool |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->regenerateRoute; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|