1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\Event; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\SPI\Repository\Decorator\LocationServiceDecorator; |
12
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
13
|
|
|
use eZ\Publish\API\Repository\LocationService as LocationServiceInterface; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentInfo; |
15
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
16
|
|
|
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct; |
17
|
|
|
use eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct; |
18
|
|
|
use eZ\Publish\Core\Event\Location\BeforeCopySubtreeEvent; |
19
|
|
|
use eZ\Publish\Core\Event\Location\BeforeCreateLocationEvent; |
20
|
|
|
use eZ\Publish\Core\Event\Location\BeforeDeleteLocationEvent; |
21
|
|
|
use eZ\Publish\Core\Event\Location\BeforeHideLocationEvent; |
22
|
|
|
use eZ\Publish\Core\Event\Location\BeforeMoveSubtreeEvent; |
23
|
|
|
use eZ\Publish\Core\Event\Location\BeforeSwapLocationEvent; |
24
|
|
|
use eZ\Publish\Core\Event\Location\BeforeUnhideLocationEvent; |
25
|
|
|
use eZ\Publish\Core\Event\Location\BeforeUpdateLocationEvent; |
26
|
|
|
use eZ\Publish\Core\Event\Location\CopySubtreeEvent; |
27
|
|
|
use eZ\Publish\Core\Event\Location\CreateLocationEvent; |
28
|
|
|
use eZ\Publish\Core\Event\Location\DeleteLocationEvent; |
29
|
|
|
use eZ\Publish\Core\Event\Location\HideLocationEvent; |
30
|
|
|
use eZ\Publish\Core\Event\Location\LocationEvents; |
31
|
|
|
use eZ\Publish\Core\Event\Location\MoveSubtreeEvent; |
32
|
|
|
use eZ\Publish\Core\Event\Location\SwapLocationEvent; |
33
|
|
|
use eZ\Publish\Core\Event\Location\UnhideLocationEvent; |
34
|
|
|
use eZ\Publish\Core\Event\Location\UpdateLocationEvent; |
35
|
|
|
|
36
|
|
|
class LocationService extends LocationServiceDecorator implements LocationServiceInterface |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
40
|
|
|
*/ |
41
|
|
|
protected $eventDispatcher; |
42
|
|
|
|
43
|
|
|
public function __construct( |
44
|
|
|
LocationServiceInterface $innerService, |
45
|
|
|
EventDispatcherInterface $eventDispatcher |
46
|
|
|
) { |
47
|
|
|
parent::__construct($innerService); |
48
|
|
|
|
49
|
|
|
$this->eventDispatcher = $eventDispatcher; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function copySubtree( |
53
|
|
|
Location $subtree, |
54
|
|
|
Location $targetParentLocation |
55
|
|
|
): Location { |
56
|
|
|
$eventData = [ |
57
|
|
|
$subtree, |
58
|
|
|
$targetParentLocation, |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
$beforeEvent = new BeforeCopySubtreeEvent(...$eventData); |
|
|
|
|
62
|
|
|
if ($this->eventDispatcher->dispatch(LocationEvents::BEFORE_COPY_SUBTREE, $beforeEvent)->isPropagationStopped()) { |
63
|
|
|
return $beforeEvent->getReturnValue(); |
64
|
|
|
} else { |
65
|
|
|
$location = parent::copySubtree($subtree, $targetParentLocation); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->eventDispatcher->dispatch( |
69
|
|
|
LocationEvents::COPY_SUBTREE, |
70
|
|
|
new CopySubtreeEvent($location, ...$eventData) |
|
|
|
|
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
return $location; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function createLocation( |
77
|
|
|
ContentInfo $contentInfo, |
78
|
|
|
LocationCreateStruct $locationCreateStruct |
79
|
|
|
): Location { |
80
|
|
|
$eventData = [ |
81
|
|
|
$contentInfo, |
82
|
|
|
$locationCreateStruct, |
83
|
|
|
]; |
84
|
|
|
|
85
|
|
|
$beforeEvent = new BeforeCreateLocationEvent(...$eventData); |
|
|
|
|
86
|
|
|
if ($this->eventDispatcher->dispatch(LocationEvents::BEFORE_CREATE_LOCATION, $beforeEvent)->isPropagationStopped()) { |
87
|
|
|
return $beforeEvent->getReturnValue(); |
88
|
|
|
} else { |
89
|
|
|
$location = parent::createLocation($contentInfo, $locationCreateStruct); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$this->eventDispatcher->dispatch( |
93
|
|
|
LocationEvents::CREATE_LOCATION, |
94
|
|
|
new CreateLocationEvent($location, ...$eventData) |
|
|
|
|
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
return $location; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function updateLocation( |
101
|
|
|
Location $location, |
102
|
|
|
LocationUpdateStruct $locationUpdateStruct |
103
|
|
|
): Location { |
104
|
|
|
$eventData = [ |
105
|
|
|
$location, |
106
|
|
|
$locationUpdateStruct, |
107
|
|
|
]; |
108
|
|
|
|
109
|
|
|
$beforeEvent = new BeforeUpdateLocationEvent(...$eventData); |
|
|
|
|
110
|
|
|
if ($this->eventDispatcher->dispatch(LocationEvents::BEFORE_UPDATE_LOCATION, $beforeEvent)->isPropagationStopped()) { |
111
|
|
|
return $beforeEvent->getReturnValue(); |
112
|
|
|
} else { |
113
|
|
|
$updatedLocation = parent::updateLocation($location, $locationUpdateStruct); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$this->eventDispatcher->dispatch( |
117
|
|
|
LocationEvents::UPDATE_LOCATION, |
118
|
|
|
new UpdateLocationEvent($updatedLocation, ...$eventData) |
|
|
|
|
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
return $updatedLocation; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
View Code Duplication |
public function swapLocation( |
125
|
|
|
Location $location1, |
126
|
|
|
Location $location2 |
127
|
|
|
): void { |
128
|
|
|
$eventData = [ |
129
|
|
|
$location1, |
130
|
|
|
$location2, |
131
|
|
|
]; |
132
|
|
|
|
133
|
|
|
$beforeEvent = new BeforeSwapLocationEvent(...$eventData); |
|
|
|
|
134
|
|
|
if ($this->eventDispatcher->dispatch(LocationEvents::BEFORE_SWAP_LOCATION, $beforeEvent)->isPropagationStopped()) { |
135
|
|
|
return $beforeEvent->getReturnValue(); |
136
|
|
|
} else { |
137
|
|
|
parent::swapLocation($location1, $location2); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
$this->eventDispatcher->dispatch( |
141
|
|
|
LocationEvents::SWAP_LOCATION, |
142
|
|
|
new SwapLocationEvent(...$eventData) |
|
|
|
|
143
|
|
|
); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
View Code Duplication |
public function hideLocation(Location $location): Location |
147
|
|
|
{ |
148
|
|
|
$eventData = [$location]; |
149
|
|
|
|
150
|
|
|
$beforeEvent = new BeforeHideLocationEvent(...$eventData); |
151
|
|
|
if ($this->eventDispatcher->dispatch(LocationEvents::BEFORE_HIDE_LOCATION, $beforeEvent)->isPropagationStopped()) { |
152
|
|
|
return $beforeEvent->getReturnValue(); |
153
|
|
|
} else { |
154
|
|
|
$hiddenLocation = parent::hideLocation($location); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$this->eventDispatcher->dispatch( |
158
|
|
|
LocationEvents::HIDE_LOCATION, |
159
|
|
|
new HideLocationEvent($hiddenLocation, ...$eventData) |
|
|
|
|
160
|
|
|
); |
161
|
|
|
|
162
|
|
|
return $hiddenLocation; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
View Code Duplication |
public function unhideLocation(Location $location): Location |
166
|
|
|
{ |
167
|
|
|
$eventData = [$location]; |
168
|
|
|
|
169
|
|
|
$beforeEvent = new BeforeUnhideLocationEvent(...$eventData); |
170
|
|
|
if ($this->eventDispatcher->dispatch(LocationEvents::BEFORE_UNHIDE_LOCATION, $beforeEvent)->isPropagationStopped()) { |
171
|
|
|
return $beforeEvent->getReturnValue(); |
172
|
|
|
} else { |
173
|
|
|
$revealedLocation = parent::unhideLocation($location); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
$this->eventDispatcher->dispatch( |
177
|
|
|
LocationEvents::UNHIDE_LOCATION, |
178
|
|
|
new UnhideLocationEvent($revealedLocation, ...$eventData) |
|
|
|
|
179
|
|
|
); |
180
|
|
|
|
181
|
|
|
return $revealedLocation; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
View Code Duplication |
public function moveSubtree( |
185
|
|
|
Location $location, |
186
|
|
|
Location $newParentLocation |
187
|
|
|
): void { |
188
|
|
|
$eventData = [ |
189
|
|
|
$location, |
190
|
|
|
$newParentLocation, |
191
|
|
|
]; |
192
|
|
|
|
193
|
|
|
$beforeEvent = new BeforeMoveSubtreeEvent(...$eventData); |
|
|
|
|
194
|
|
|
if ($this->eventDispatcher->dispatch(LocationEvents::BEFORE_MOVE_SUBTREE, $beforeEvent)->isPropagationStopped()) { |
195
|
|
|
return; |
196
|
|
|
} else { |
197
|
|
|
parent::moveSubtree($location, $newParentLocation); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
$this->eventDispatcher->dispatch( |
201
|
|
|
LocationEvents::MOVE_SUBTREE, |
202
|
|
|
new MoveSubtreeEvent(...$eventData) |
|
|
|
|
203
|
|
|
); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function deleteLocation(Location $location): void |
207
|
|
|
{ |
208
|
|
|
$eventData = [$location]; |
209
|
|
|
|
210
|
|
|
$beforeEvent = new BeforeDeleteLocationEvent(...$eventData); |
211
|
|
|
if ($this->eventDispatcher->dispatch(LocationEvents::BEFORE_DELETE_LOCATION, $beforeEvent)->isPropagationStopped()) { |
212
|
|
|
return $beforeEvent->getReturnValue(); |
213
|
|
|
} else { |
214
|
|
|
parent::deleteLocation($location); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
$this->eventDispatcher->dispatch( |
218
|
|
|
LocationEvents::DELETE_LOCATION, |
219
|
|
|
new DeleteLocationEvent(...$eventData) |
220
|
|
|
); |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|
This check looks for function calls that miss required arguments.