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

Output/ValueObjectVisitor/RestRelation.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\Content\Relation as RelationValue;
13
17 class RestRelation extends ValueObjectVisitor
18 {
26 public function visit(Visitor $visitor, Generator $generator, $data)
27 {
28 $generator->startObjectElement('Relation');
29 $visitor->setHeader('Content-Type', $generator->getMediaType('Relation'));
30
31 $generator->startAttribute(
32 'href',
33 $this->router->generate(
34 'ezpublish_rest_loadVersionRelation',
35 [
36 'contentId' => $data->contentId,
37 'versionNumber' => $data->versionNo,
38 'relationId' => $data->relation->id,
39 ]
40 )
41 );
42 $generator->endAttribute('href');
43
44 $generator->startObjectElement('SourceContent', 'ContentInfo');
45 $generator->startAttribute(
46 'href',
47 $this->router->generate(
48 'ezpublish_rest_loadContent',
49 [
50 'contentId' => $data->contentId,
51 ]
52 )
53 );
54 $generator->endAttribute('href');
55 $generator->endObjectElement('SourceContent');
56
57 $generator->startObjectElement('DestinationContent', 'ContentInfo');
58 $generator->startAttribute(
59 'href',
60 $this->router->generate(
61 'ezpublish_rest_loadContent',
62 [
63 'contentId' => $data->relation->getDestinationContentInfo()->id,
64 ]
65 )
66 );
67 $generator->endAttribute('href');
68 $generator->endObjectElement('DestinationContent');
69
70 if ($data->relation->sourceFieldDefinitionIdentifier !== null) {
71 $generator->startValueElement('SourceFieldDefinitionIdentifier', $data->relation->sourceFieldDefinitionIdentifier);
72 $generator->endValueElement('SourceFieldDefinitionIdentifier');
73 }
74
75 $generator->startValueElement('RelationType', $this->getRelationTypeString($data->relation->type));
76 $generator->endValueElement('RelationType');
77
78 $generator->endObjectElement('Relation');
79 }
80
90 protected function getRelationTypeString($relationType)
91 {
92 $relationTypeList = [];
93
94 if (RelationValue::COMMON & $relationType) {
95 $relationTypeList[] = 'COMMON';
96 }
97 if (RelationValue::EMBED & $relationType) {
98 $relationTypeList[] = 'EMBED';
99 }
100 if (RelationValue::LINK & $relationType) {
101 $relationTypeList[] = 'LINK';
102 }
103 if (RelationValue::FIELD & $relationType) {
104 $relationTypeList[] = 'ATTRIBUTE';
105 }
106 if (RelationValue::ASSET & $relationType) {
107 $relationTypeList[] = 'ASSET';
108 }
109
110 if (empty($relationTypeList)) {
111 throw new \Exception('Unknown relation type ' . $relationType . '.');
112 }
113
114 return implode(',', $relationTypeList);
115 }
116 }
eZ\Publish\API\Repository\Values\Content\Relation
Definition: API/Repository/Values/Content/Relation.php:21
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\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\RestRelation
RestRelation value object visitor.
Definition: Output/ValueObjectVisitor/RestRelation.php:18
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestRelation\visit
visit(Visitor $visitor, Generator $generator, $data)
Visit struct returned by controllers.
Definition: Output/ValueObjectVisitor/RestRelation.php:26
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestRelation\getRelationTypeString
getRelationTypeString($relationType)
Returns $relationType as a readable string.
Definition: Output/ValueObjectVisitor/RestRelation.php:90
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+.