1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Synapse\Page\Bundle\Action\Page; |
4
|
|
|
|
5
|
|
|
use Synapse\Page\Bundle\Entity\Page; |
6
|
|
|
use Synapse\Page\Bundle\Event\Page\Event as PageEvent; |
7
|
|
|
use Synapse\Page\Bundle\Event\Page\Events as PageEvents; |
8
|
|
|
use Synapse\Page\Bundle\Generator\PathGeneratorInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Page creation action representation. |
12
|
|
|
*/ |
13
|
|
|
class CreateAction extends AbstractAction |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var Page |
17
|
|
|
*/ |
18
|
|
|
protected $parent; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $path; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $fullPath; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var PathGeneratorInterface |
32
|
|
|
*/ |
33
|
|
|
protected $pathGenerator; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Construct. |
37
|
|
|
* |
38
|
|
|
* @param PathGeneratorInterface $pathGenerator |
39
|
|
|
*/ |
40
|
|
|
public function __construct(PathGeneratorInterface $pathGenerator) |
41
|
|
|
{ |
42
|
|
|
$this->pathGenerator = $pathGenerator; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Initialisation function. |
47
|
|
|
* |
48
|
|
|
* @param Page $page |
49
|
|
|
*/ |
50
|
|
|
public function init(Page $page = null) |
51
|
|
|
{ |
52
|
|
|
$this->page = new Page(); |
53
|
|
|
|
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Page creation method. |
59
|
|
|
* |
60
|
|
|
* @return Page |
61
|
|
|
*/ |
62
|
|
|
public function resolve() |
63
|
|
|
{ |
64
|
|
|
$this->page |
65
|
|
|
->setName($this->name) |
66
|
|
|
->setOnline(!empty($this->online)) |
67
|
|
|
->setTitle($this->title) |
68
|
|
|
->setMeta(array('title' => $this->title)) |
69
|
|
|
->setPath($this->getFullPath()) |
70
|
|
|
; |
71
|
|
|
|
72
|
|
|
$this->assertEntityIsValid($this->page, array('Page', 'creation')); |
73
|
|
|
|
74
|
|
|
$this->fireEvent( |
75
|
|
|
PageEvents::PAGE_CREATED, |
76
|
|
|
new PageEvent($this->page, $this) |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
return $this->page; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Returns action parent. |
84
|
|
|
* |
85
|
|
|
* @return Page|null |
86
|
|
|
*/ |
87
|
|
|
public function getParent() |
88
|
|
|
{ |
89
|
|
|
return $this->parent; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Define action parent. |
94
|
|
|
* |
95
|
|
|
* @param Page $parent |
96
|
|
|
* |
97
|
|
|
* @return self |
98
|
|
|
*/ |
99
|
|
|
public function setParent(Page $parent = null) |
100
|
|
|
{ |
101
|
|
|
$this->page->setParent($parent); |
102
|
|
|
|
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Returns action path. |
108
|
|
|
* |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
public function getPath() |
112
|
|
|
{ |
113
|
|
|
return $this->path; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Define action path. |
118
|
|
|
* |
119
|
|
|
* @param string $path |
120
|
|
|
* |
121
|
|
|
* @return self |
122
|
|
|
*/ |
123
|
|
|
public function setPath($path) |
124
|
|
|
{ |
125
|
|
|
$this->path = $path; |
126
|
|
|
$this->fullPath = null; |
127
|
|
|
|
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Generate page full path. |
133
|
|
|
* |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
|
|
protected function generateFullPath() |
137
|
|
|
{ |
138
|
|
|
return $this->fullPath = $this->pathGenerator |
139
|
|
|
->generatePath($this->page, $this->path ?: '') |
140
|
|
|
; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Returns action full path. |
145
|
|
|
* |
146
|
|
|
* @return string |
147
|
|
|
*/ |
148
|
|
|
public function getFullPath() |
149
|
|
|
{ |
150
|
|
|
return $this->fullPath ?: $this->generateFullPath(); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|