Completed
Push — ezp-30616 ( 9239a0...7bf8e8 )
by
unknown
57:53 queued 37:56
created

URLWildcardService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 135
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 135
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 13 1
A remove() 0 13 1
A load() 0 4 1
A loadAll() 0 4 1
A translate() 0 13 1
1
<?php
2
3
/**
4
 * URLWildcardService class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\SignalSlot;
10
11
use eZ\Publish\API\Repository\URLWildcardService as URLWildcardServiceInterface;
12
use eZ\Publish\API\Repository\Values\Content\URLWildcard;
13
use eZ\Publish\Core\SignalSlot\Signal\URLWildcardService\CreateSignal;
14
use eZ\Publish\Core\SignalSlot\Signal\URLWildcardService\RemoveSignal;
15
use eZ\Publish\Core\SignalSlot\Signal\URLWildcardService\TranslateSignal;
16
17
/**
18
 * URLWildcardService class.
19
 */
20
class URLWildcardService implements URLWildcardServiceInterface
21
{
22
    /**
23
     * Aggregated service.
24
     *
25
     * @var \eZ\Publish\API\Repository\URLWildcardService
26
     */
27
    protected $service;
28
29
    /**
30
     * SignalDispatcher.
31
     *
32
     * @var \eZ\Publish\Core\SignalSlot\SignalDispatcher
33
     */
34
    protected $signalDispatcher;
35
36
    /**
37
     * Constructor.
38
     *
39
     * Construct service object from aggregated service and signal
40
     * dispatcher
41
     *
42
     * @param \eZ\Publish\API\Repository\URLWildcardService $service
43
     * @param \eZ\Publish\Core\SignalSlot\SignalDispatcher $signalDispatcher
44
     */
45
    public function __construct(URLWildcardServiceInterface $service, SignalDispatcher $signalDispatcher)
46
    {
47
        $this->service = $service;
48
        $this->signalDispatcher = $signalDispatcher;
49
    }
50
51
    /**
52
     * Creates a new url wildcard.
53
     *
54
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the $sourceUrl pattern already exists
55
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create url wildcards
56
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if the number of "*" patterns in $sourceUrl and
57
     *          the number of {\d} placeholders in $destinationUrl doesn't match or
58
     *          if the placeholders aren't a valid number sequence({1}/{2}/{3}), starting with 1.
59
     *
60
     * @param string $sourceUrl
61
     * @param string $destinationUrl
62
     * @param bool $forward
63
     *
64
     * @return \eZ\Publish\API\Repository\Values\Content\UrlWildcard
65
     */
66
    public function create($sourceUrl, $destinationUrl, $forward = false)
67
    {
68
        $returnValue = $this->service->create($sourceUrl, $destinationUrl, $forward);
69
        $this->signalDispatcher->emit(
70
            new CreateSignal(
71
                array(
72
                    'urlWildcardId' => $returnValue->id,
73
                )
74
            )
75
        );
76
77
        return $returnValue;
78
    }
79
80
    /**
81
     * removes an url wildcard.
82
     *
83
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove url wildcards
84
     *
85
     * @param \eZ\Publish\API\Repository\Values\Content\URLWildcard $urlWildcard the url wildcard to remove
86
     */
87
    public function remove(URLWildcard $urlWildcard)
88
    {
89
        $returnValue = $this->service->remove($urlWildcard);
90
        $this->signalDispatcher->emit(
91
            new RemoveSignal(
92
                array(
93
                    'urlWildcardId' => $urlWildcard->id,
94
                )
95
            )
96
        );
97
98
        return $returnValue;
99
    }
100
101
    /**
102
     * Loads a url wild card.
103
     *
104
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the url wild card was not found
105
     *
106
     * @param mixed $id
107
     *
108
     * @return \eZ\Publish\API\Repository\Values\Content\UrlWildcard
109
     */
110
    public function load($id)
111
    {
112
        return $this->service->load($id);
113
    }
114
115
    /**
116
     * Loads all url wild card (paged).
117
     *
118
     * @param int $offset
119
     * @param int $limit
120
     *
121
     * @return \eZ\Publish\API\Repository\Values\Content\UrlWildcard[]
122
     */
123
    public function loadAll($offset = 0, $limit = -1)
124
    {
125
        return $this->service->loadAll($offset, $limit);
126
    }
127
128
    /**
129
     * translates an url to an existing uri resource based on the
130
     * source/destination patterns of the url wildcard. If the resulting
131
     * url is an alias it will be translated to the system uri.
132
     *
133
     * This method runs also configured url translations and filter
134
     *
135
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the url could not be translated
136
     *
137
     * @param mixed $url
138
     *
139
     * @return \eZ\Publish\API\Repository\Values\Content\URLWildcardTranslationResult
140
     */
141
    public function translate($url)
142
    {
143
        $returnValue = $this->service->translate($url);
144
        $this->signalDispatcher->emit(
145
            new TranslateSignal(
146
                array(
147
                    'url' => $url,
148
                )
149
            )
150
        );
151
152
        return $returnValue;
153
    }
154
}
155