|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the URLAlias 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; |
|
15
|
|
|
use eZ\Publish\API\Repository\Values\Content\URLAlias as URLAliasValue; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* URLAlias value object visitor. |
|
19
|
|
|
*/ |
|
20
|
|
|
class URLAlias extends ValueObjectVisitor |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Visit struct returned by controllers. |
|
24
|
|
|
* |
|
25
|
|
|
* @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor |
|
26
|
|
|
* @param \eZ\Publish\Core\REST\Common\Output\Generator $generator |
|
27
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\URLAlias $data |
|
28
|
|
|
*/ |
|
29
|
|
|
public function visit(Visitor $visitor, Generator $generator, $data) |
|
30
|
|
|
{ |
|
31
|
|
|
$generator->startObjectElement('UrlAlias'); |
|
32
|
|
|
$visitor->setHeader('Content-Type', $generator->getMediaType('UrlAlias')); |
|
33
|
|
|
$this->visitURLAliasAttributes($visitor, $generator, $data); |
|
34
|
|
|
$generator->endObjectElement('UrlAlias'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Serializes the given $urlAliasType to a string representation. |
|
39
|
|
|
* |
|
40
|
|
|
* @param int $urlAliasType |
|
41
|
|
|
* |
|
42
|
|
|
* @return string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function serializeType($urlAliasType) |
|
45
|
|
|
{ |
|
46
|
|
|
switch ($urlAliasType) { |
|
47
|
|
|
case Values\Content\URLAlias::LOCATION: |
|
48
|
|
|
return 'LOCATION'; |
|
49
|
|
|
|
|
50
|
|
|
case Values\Content\URLAlias::RESOURCE: |
|
51
|
|
|
return 'RESOURCE'; |
|
52
|
|
|
|
|
53
|
|
|
case Values\Content\URLAlias::VIRTUAL: |
|
54
|
|
|
return 'VIRTUAL'; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
throw new \RuntimeException("Unknown URL alias type: '{$urlAliasType}'."); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
protected function visitURLAliasAttributes(Visitor $visitor, Generator $generator, URLAliasValue $data) |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
|
|
$generator->startAttribute( |
|
63
|
|
|
'href', |
|
64
|
|
|
$this->router->generate('ezpublish_rest_loadURLAlias', array('urlAliasId' => $data->id)) |
|
65
|
|
|
); |
|
66
|
|
|
$generator->endAttribute('href'); |
|
67
|
|
|
|
|
68
|
|
|
$generator->startAttribute('id', $data->id); |
|
69
|
|
|
$generator->endAttribute('id'); |
|
70
|
|
|
|
|
71
|
|
|
$generator->startAttribute('type', $this->serializeType($data->type)); |
|
72
|
|
|
$generator->endAttribute('type'); |
|
73
|
|
|
|
|
74
|
|
|
if ($data->type === Values\Content\URLAlias::LOCATION) { |
|
75
|
|
|
$generator->startObjectElement('location', 'Location'); |
|
76
|
|
|
$generator->startAttribute( |
|
77
|
|
|
'href', |
|
78
|
|
|
$this->router->generate('ezpublish_rest_loadLocation', array('locationPath' => $data->destination)) |
|
79
|
|
|
); |
|
80
|
|
|
$generator->endAttribute('href'); |
|
81
|
|
|
$generator->endObjectElement('location'); |
|
82
|
|
|
} else { |
|
83
|
|
|
$generator->startValueElement('resource', $data->destination); |
|
84
|
|
|
$generator->endValueElement('resource'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$generator->startValueElement('path', $data->path); |
|
88
|
|
|
$generator->endValueElement('path'); |
|
89
|
|
|
|
|
90
|
|
|
$generator->startValueElement('languageCodes', implode(',', $data->languageCodes)); |
|
91
|
|
|
$generator->endValueElement('languageCodes'); |
|
92
|
|
|
|
|
93
|
|
|
$generator->startValueElement( |
|
94
|
|
|
'alwaysAvailable', |
|
95
|
|
|
$this->serializeBool($generator, $data->alwaysAvailable) |
|
96
|
|
|
); |
|
97
|
|
|
$generator->endValueElement('alwaysAvailable'); |
|
98
|
|
|
|
|
99
|
|
|
$generator->startValueElement( |
|
100
|
|
|
'isHistory', |
|
101
|
|
|
$this->serializeBool($generator, $data->isHistory) |
|
102
|
|
|
); |
|
103
|
|
|
$generator->endValueElement('isHistory'); |
|
104
|
|
|
|
|
105
|
|
|
$generator->startValueElement( |
|
106
|
|
|
'forward', |
|
107
|
|
|
$this->serializeBool($generator, $data->forward) |
|
108
|
|
|
); |
|
109
|
|
|
$generator->endValueElement('forward'); |
|
110
|
|
|
|
|
111
|
|
|
$generator->startValueElement( |
|
112
|
|
|
'custom', |
|
113
|
|
|
$this->serializeBool($generator, $data->isCustom) |
|
114
|
|
|
); |
|
115
|
|
|
$generator->endValueElement('custom'); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.