1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the URLWildcard ValueObjectVisitor 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\REST\Server\Output\ValueObjectVisitor; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor; |
12
|
|
|
use eZ\Publish\Core\REST\Common\Output\Generator; |
13
|
|
|
use eZ\Publish\Core\REST\Common\Output\Visitor; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\URLWildcard as URLWildcardValue; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* URLWildcard value object visitor. |
18
|
|
|
*/ |
19
|
|
View Code Duplication |
class URLWildcard extends ValueObjectVisitor |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Visit struct returned by controllers. |
23
|
|
|
* |
24
|
|
|
* @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor |
25
|
|
|
* @param \eZ\Publish\Core\REST\Common\Output\Generator $generator |
26
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\URLWildcard $data |
27
|
|
|
*/ |
28
|
|
|
public function visit(Visitor $visitor, Generator $generator, $data) |
29
|
|
|
{ |
30
|
|
|
$visitor->setHeader('Content-Type', $generator->getMediaType('UrlWildcard')); |
31
|
|
|
$generator->startObjectElement('UrlWildcard'); |
32
|
|
|
$this->visitURLWildcardAttributes($visitor, $generator, $data); |
33
|
|
|
$generator->endObjectElement('UrlWildcard'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function visitURLWildcardAttributes(Visitor $visitor, Generator $generator, URLWildcardValue $data) |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$generator->startAttribute( |
39
|
|
|
'href', |
40
|
|
|
$this->router->generate('ezpublish_rest_loadURLWildcard', array('urlWildcardId' => $data->id)) |
41
|
|
|
); |
42
|
|
|
$generator->endAttribute('href'); |
43
|
|
|
|
44
|
|
|
$generator->startAttribute('id', $data->id); |
45
|
|
|
$generator->endAttribute('id'); |
46
|
|
|
|
47
|
|
|
$generator->startValueElement('sourceUrl', $data->sourceUrl); |
48
|
|
|
$generator->endValueElement('sourceUrl'); |
49
|
|
|
|
50
|
|
|
$generator->startValueElement('destinationUrl', $data->destinationUrl); |
51
|
|
|
$generator->endValueElement('destinationUrl'); |
52
|
|
|
|
53
|
|
|
$generator->startValueElement( |
54
|
|
|
'forward', |
55
|
|
|
$this->serializeBool($generator, $data->forward) |
56
|
|
|
); |
57
|
|
|
$generator->endValueElement('forward'); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.