Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Core/REST/Server/Output/ValueObjectVisitor/URLAlias.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
8
9 use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
10 use eZ\Publish\Core\REST\Common\Output\Generator;
11 use eZ\Publish\Core\REST\Common\Output\Visitor;
12 use eZ\Publish\API\Repository\Values;
13 use eZ\Publish\API\Repository\Values\Content\URLAlias as URLAliasValue;
14
18 class URLAlias extends ValueObjectVisitor
19 {
27 public function visit(Visitor $visitor, Generator $generator, $data)
28 {
29 $generator->startObjectElement('UrlAlias');
30 $visitor->setHeader('Content-Type', $generator->getMediaType('UrlAlias'));
31 $this->visitURLAliasAttributes($visitor, $generator, $data);
32 $generator->endObjectElement('UrlAlias');
33 }
34
42 protected function serializeType($urlAliasType)
43 {
44 switch ($urlAliasType) {
45 case Values\Content\URLAlias::LOCATION:
46 return 'LOCATION';
47
48 case Values\Content\URLAlias::RESOURCE:
49 return 'RESOURCE';
50
51 case Values\Content\URLAlias::VIRTUAL:
52 return 'VIRTUAL';
53 }
54
55 throw new \RuntimeException("Unknown URL alias type: '{$urlAliasType}'.");
56 }
57
58 protected function visitURLAliasAttributes(Visitor $visitor, Generator $generator, URLAliasValue $data)
59 {
60 $generator->startAttribute(
61 'href',
62 $this->router->generate('ezpublish_rest_loadURLAlias', ['urlAliasId' => $data->id])
63 );
64 $generator->endAttribute('href');
65
66 $generator->startAttribute('id', $data->id);
67 $generator->endAttribute('id');
68
69 $generator->startAttribute('type', $this->serializeType($data->type));
70 $generator->endAttribute('type');
71
72 if ($data->type === Values\Content\URLAlias::LOCATION) {
73 $generator->startObjectElement('location', 'Location');
74 $generator->startAttribute(
75 'href',
76 $this->router->generate('ezpublish_rest_loadLocation', ['locationPath' => $data->destination])
77 );
78 $generator->endAttribute('href');
79 $generator->endObjectElement('location');
80 } else {
81 $generator->startValueElement('resource', $data->destination);
82 $generator->endValueElement('resource');
83 }
84
85 $generator->startValueElement('path', $data->path);
86 $generator->endValueElement('path');
87
88 $generator->startValueElement('languageCodes', implode(',', $data->languageCodes));
89 $generator->endValueElement('languageCodes');
90
91 $generator->startValueElement(
92 'alwaysAvailable',
93 $this->serializeBool($generator, $data->alwaysAvailable)
94 );
95 $generator->endValueElement('alwaysAvailable');
96
97 $generator->startValueElement(
98 'isHistory',
99 $this->serializeBool($generator, $data->isHistory)
100 );
101 $generator->endValueElement('isHistory');
102
103 $generator->startValueElement(
104 'forward',
105 $this->serializeBool($generator, $data->forward)
106 );
107 $generator->endValueElement('forward');
108
109 $generator->startValueElement(
110 'custom',
111 $this->serializeBool($generator, $data->isCustom)
112 );
113 $generator->endValueElement('custom');
114 }
115 }
eZ\Publish\API\Repository\Values\Content\Content
Definition: Publish/API/Repository/Values/Content/Content.php:21
eZ\Publish\API\Repository\Values\Content\URLAlias
Definition: API/Repository/Values/Content/URLAlias.php:25
eZ\Publish\Core\REST\Common\Output\Generator
Output generator.
Definition: REST/Common/Output/Generator.php:13
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor
Basic ValueObjectVisitor.
Definition: ValueObjectVisitor.php:18
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor\serializeBool
serializeBool(Generator $generator, $boolValue)
Returns a string representation for the given $boolValue.
Definition: ValueObjectVisitor.php:67
eZ\Publish\Core\REST\Common\Output\Visitor
Visits a value object into an HTTP Response.
Definition: Visitor.php:15
eZ\Publish\Core\REST\Common\Output\Visitor\setHeader
setHeader($name, $value)
Set HTTP response header.
Definition: Visitor.php:64
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\URLAlias
URLAlias value object visitor.
Definition: Core/REST/Server/Output/ValueObjectVisitor/URLAlias.php:19
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\URLAlias\visit
visit(Visitor $visitor, Generator $generator, $data)
Visit struct returned by controllers.
Definition: Core/REST/Server/Output/ValueObjectVisitor/URLAlias.php:27
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\URLAlias\visitURLAliasAttributes
visitURLAliasAttributes(Visitor $visitor, Generator $generator, URLAliasValue $data)
Definition: Core/REST/Server/Output/ValueObjectVisitor/URLAlias.php:58
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\URLAlias\serializeType
serializeType($urlAliasType)
Serializes the given $urlAliasType to a string representation.
Definition: Core/REST/Server/Output/ValueObjectVisitor/URLAlias.php:42
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor
Definition: Common/Output/ValueObjectVisitor/ContentObjectStates.php:7
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor
Definition: Output/ValueObjectVisitor/BadRequestException.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.