|
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\API\Repository\Events; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Events\URL\BeforeUpdateUrlEvent as BeforeUpdateUrlEventInterface; |
|
12
|
|
|
use eZ\Publish\API\Repository\Events\URL\UpdateUrlEvent as UpdateUrlEventInterface; |
|
13
|
|
|
use eZ\Publish\API\Repository\URLService as URLServiceInterface; |
|
14
|
|
|
use eZ\Publish\API\Repository\Values\URL\URL; |
|
15
|
|
|
use eZ\Publish\API\Repository\Values\URL\URLUpdateStruct; |
|
16
|
|
|
use eZ\Publish\API\Repository\Events\URL\BeforeUpdateUrlEvent; |
|
17
|
|
|
use eZ\Publish\API\Repository\Events\URL\UpdateUrlEvent; |
|
18
|
|
|
use eZ\Publish\SPI\Repository\Decorator\URLServiceDecorator; |
|
19
|
|
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
|
20
|
|
|
|
|
21
|
|
|
class URLService extends URLServiceDecorator |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface */ |
|
24
|
|
|
protected $eventDispatcher; |
|
25
|
|
|
|
|
26
|
|
|
public function __construct( |
|
27
|
|
|
URLServiceInterface $innerService, |
|
28
|
|
|
EventDispatcherInterface $eventDispatcher |
|
29
|
|
|
) { |
|
30
|
|
|
parent::__construct($innerService); |
|
31
|
|
|
|
|
32
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function updateUrl( |
|
36
|
|
|
URL $url, |
|
37
|
|
|
URLUpdateStruct $struct |
|
38
|
|
|
) { |
|
39
|
|
|
$eventData = [ |
|
40
|
|
|
$url, |
|
41
|
|
|
$struct, |
|
42
|
|
|
]; |
|
43
|
|
|
|
|
44
|
|
|
$beforeEvent = new BeforeUpdateUrlEvent(...$eventData); |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
$this->eventDispatcher->dispatch($beforeEvent, BeforeUpdateUrlEventInterface::class); |
|
47
|
|
|
if ($beforeEvent->isPropagationStopped()) { |
|
48
|
|
|
return $beforeEvent->getUpdatedUrl(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$updatedUrl = $beforeEvent->hasUpdatedUrl() |
|
52
|
|
|
? $beforeEvent->getUpdatedUrl() |
|
53
|
|
|
: $this->innerService->updateUrl($url, $struct); |
|
54
|
|
|
|
|
55
|
|
|
$this->eventDispatcher->dispatch( |
|
56
|
|
|
new UpdateUrlEvent($updatedUrl, ...$eventData), |
|
|
|
|
|
|
57
|
|
|
UpdateUrlEventInterface::class |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
return $updatedUrl; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
This check looks for function calls that miss required arguments.