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\URLWildcardServiceDecorator; |
12
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
13
|
|
|
use eZ\Publish\API\Repository\URLWildcardService as URLWildcardServiceInterface; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\URLWildcard; |
15
|
|
|
use eZ\Publish\Core\Event\URLWildcard\BeforeCreateEvent; |
16
|
|
|
use eZ\Publish\Core\Event\URLWildcard\BeforeRemoveEvent; |
17
|
|
|
use eZ\Publish\Core\Event\URLWildcard\BeforeTranslateEvent; |
18
|
|
|
use eZ\Publish\Core\Event\URLWildcard\CreateEvent; |
19
|
|
|
use eZ\Publish\Core\Event\URLWildcard\RemoveEvent; |
20
|
|
|
use eZ\Publish\Core\Event\URLWildcard\TranslateEvent; |
21
|
|
|
use eZ\Publish\Core\Event\URLWildcard\URLWildcardEvents; |
22
|
|
|
|
23
|
|
|
class URLWildcardService extends URLWildcardServiceDecorator implements URLWildcardServiceInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
27
|
|
|
*/ |
28
|
|
|
protected $eventDispatcher; |
29
|
|
|
|
30
|
|
|
public function __construct( |
31
|
|
|
URLWildcardServiceInterface $innerService, |
32
|
|
|
EventDispatcherInterface $eventDispatcher |
33
|
|
|
) { |
34
|
|
|
parent::__construct($innerService); |
35
|
|
|
|
36
|
|
|
$this->eventDispatcher = $eventDispatcher; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
View Code Duplication |
public function create( |
40
|
|
|
$sourceUrl, |
41
|
|
|
$destinationUrl, |
42
|
|
|
$forward = false |
43
|
|
|
) { |
44
|
|
|
$eventData = [ |
45
|
|
|
$sourceUrl, |
46
|
|
|
$destinationUrl, |
47
|
|
|
$forward, |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
$beforeEvent = new BeforeCreateEvent(...$eventData); |
|
|
|
|
51
|
|
|
if ($this->eventDispatcher->dispatch(URLWildcardEvents::BEFORE_CREATE, $beforeEvent)->isPropagationStopped()) { |
52
|
|
|
return $beforeEvent->getReturnValue(); |
53
|
|
|
} else { |
54
|
|
|
$urlWildcard = parent::create($sourceUrl, $destinationUrl, $forward); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$this->eventDispatcher->dispatch( |
58
|
|
|
URLWildcardEvents::CREATE, |
59
|
|
|
new CreateEvent($urlWildcard, ...$eventData) |
|
|
|
|
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
return $urlWildcard; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function remove(URLWildcard $urlWildcard) |
66
|
|
|
{ |
67
|
|
|
$eventData = [$urlWildcard]; |
68
|
|
|
|
69
|
|
|
$beforeEvent = new BeforeRemoveEvent(...$eventData); |
70
|
|
|
if ($this->eventDispatcher->dispatch(URLWildcardEvents::BEFORE_REMOVE, $beforeEvent)->isPropagationStopped()) { |
71
|
|
|
return; |
72
|
|
|
} else { |
73
|
|
|
parent::remove($urlWildcard); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$this->eventDispatcher->dispatch( |
77
|
|
|
URLWildcardEvents::REMOVE, |
78
|
|
|
new RemoveEvent(...$eventData) |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
View Code Duplication |
public function translate($url) |
83
|
|
|
{ |
84
|
|
|
$eventData = [$url]; |
85
|
|
|
|
86
|
|
|
$beforeEvent = new BeforeTranslateEvent(...$eventData); |
87
|
|
|
if ($this->eventDispatcher->dispatch(URLWildcardEvents::BEFORE_TRANSLATE, $beforeEvent)->isPropagationStopped()) { |
88
|
|
|
return $beforeEvent->getReturnValue(); |
89
|
|
|
} else { |
90
|
|
|
$result = parent::translate($url); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$this->eventDispatcher->dispatch( |
94
|
|
|
URLWildcardEvents::TRANSLATE, |
95
|
|
|
new TranslateEvent($result, ...$eventData) |
|
|
|
|
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
return $result; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|