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

Output/ValueObjectVisitor/RestExecutedView.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\API\Repository\Exceptions\NotFoundException;
10 use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;
11 use eZ\Publish\API\Repository\Values\Content as ApiValues;
12 use eZ\Publish\Core\REST\Common\Exceptions;
13 use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
14 use eZ\Publish\Core\REST\Common\Output\Generator;
15 use eZ\Publish\Core\REST\Common\Output\Visitor;
16 use eZ\Publish\API\Repository\ContentService;
17 use eZ\Publish\API\Repository\LocationService;
18 use eZ\Publish\Core\REST\Server\Values\RestContent as RestContentValue;
19
23 class RestExecutedView extends ValueObjectVisitor
24 {
30 protected $locationService;
31
37 protected $contentService;
38
43 public function __construct(
44 LocationService $locationService,
45 ContentService $contentService
46 ) {
47 $this->locationService = $locationService;
48 $this->contentService = $contentService;
49 }
50
58 public function visit(Visitor $visitor, Generator $generator, $data)
59 {
60 $generator->startObjectElement('View');
61 $visitor->setHeader('Content-Type', $generator->getMediaType('View'));
62
63 $generator->startAttribute(
64 'href',
65 $this->router->generate('ezpublish_rest_views_load', ['viewId' => $data->identifier])
66 );
67 $generator->endAttribute('href');
68
69 $generator->startValueElement('identifier', $data->identifier);
70 $generator->endValueElement('identifier');
71
72 // BEGIN Query
73 $generator->startObjectElement('Query');
74 $generator->endObjectElement('Query');
75 // END Query
76
77 // BEGIN Result
78 $generator->startObjectElement('Result', 'ViewResult');
79 $generator->startAttribute(
80 'href',
81 $this->router->generate('ezpublish_rest_views_load_results', ['viewId' => $data->identifier])
82 );
83 $generator->endAttribute('href');
84
85 // BEGIN Result metadata
86 $generator->startValueElement('count', $data->searchResults->totalCount);
87 $generator->endValueElement('count');
88
89 $generator->startValueElement('time', $data->searchResults->time);
90 $generator->endValueElement('time');
91
92 $generator->startValueElement('timedOut', $generator->serializeBool($data->searchResults->timedOut));
93 $generator->endValueElement('timedOut');
94
95 $generator->startValueElement('maxScore', $data->searchResults->maxScore);
96 $generator->endValueElement('maxScore');
97 // END Result metadata
98
99 // BEGIN searchHits
100 $generator->startHashElement('searchHits');
101 $generator->startList('searchHit');
102
103 foreach ($data->searchResults->searchHits as $searchHit) {
104 $generator->startObjectElement('searchHit');
105
106 $generator->startAttribute('score', (float)$searchHit->score);
107 $generator->endAttribute('score');
108
109 $generator->startAttribute('index', (string)$searchHit->index);
110 $generator->endAttribute('index');
111
112 $generator->startObjectElement('value');
113
114 // @todo Refactor
115 if ($searchHit->valueObject instanceof ApiValues\Content) {
117 $contentInfo = $searchHit->valueObject->contentInfo;
118
119 try {
120 $mainLocation = $this->locationService->loadLocation($contentInfo->mainLocationId);
121 } catch (NotFoundException | UnauthorizedException $e) {
122 $mainLocation = null;
123 }
124
125 $valueObject = new RestContentValue(
126 $contentInfo,
127 $mainLocation,
128 $searchHit->valueObject,
129 $searchHit->valueObject->getContentType(),
130 $this->contentService->loadRelations($searchHit->valueObject->getVersionInfo())
131 );
132 } elseif ($searchHit->valueObject instanceof ApiValues\Location) {
133 $valueObject = $searchHit->valueObject;
134 } elseif ($searchHit->valueObject instanceof ApiValues\ContentInfo) {
135 $valueObject = new RestContentValue($searchHit->valueObject);
136 } else {
137 throw new Exceptions\InvalidArgumentException('Unhandled object type');
138 }
139
140 $visitor->visitValueObject($valueObject);
141 $generator->endObjectElement('value');
142 $generator->endObjectElement('searchHit');
143 }
144
145 $generator->endList('searchHit');
146
147 $generator->endHashElement('searchHits');
148 // END searchHits
149
150 $generator->endObjectElement('Result');
151 // END Result
152
153 $generator->endObjectElement('View');
154 }
155 }
eZ\Publish\API\Repository\Exceptions\NotFoundException
This Exception is thrown if an object referenced by an id or identifier could not be found in the rep...
Definition: API/Repository/Exceptions/NotFoundException.php:16
eZ\Publish\API\Repository\Exceptions\UnauthorizedException
This Exception is thrown if the user has is not allowed to perform a service operation.
Definition: API/Repository/Exceptions/UnauthorizedException.php:15
eZ\Publish\API\Repository\Values\Content\Content
Definition: Publish/API/Repository/Values/Content/Content.php:21
eZ\Publish\Core\REST\Common\Exceptions\NotFoundException
Implementation of the \eZ\Publish\API\Repository\Exceptions\NotFoundException interface.
Definition: Core/REST/Common/Exceptions/NotFoundException.php:18
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\visit
visit(Visitor $visitor, Generator $generator, $data)
Visit struct returned by controllers.
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\visitValueObject
visitValueObject($data)
Visit struct returned by controllers.
Definition: Visitor.php:131
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\RestExecutedView
Section value object visitor.
Definition: Output/ValueObjectVisitor/RestExecutedView.php:24
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestExecutedView\$contentService
$contentService
Definition: Output/ValueObjectVisitor/RestExecutedView.php:37
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestExecutedView\__construct
__construct(LocationService $locationService, ContentService $contentService)
Definition: Output/ValueObjectVisitor/RestExecutedView.php:43
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestExecutedView\$locationService
$locationService
Definition: Output/ValueObjectVisitor/RestExecutedView.php:30
eZ\Publish\Core\REST\Server\Values\RestContent
REST Content, as received by /content/objects/<ID>.
Definition: Values/RestContent.php:21
eZ\Publish\API\Repository\ContentService
Definition: API/Repository/ContentService.php:27
eZ\Publish\API\Repository\LocationService
Definition: API/Repository/LocationService.php:21
eZ\Publish\API\Repository\Values\Content
Definition: Publish/API/Repository/Values/Content/Content.php:7
eZ\Publish\Core\REST\Common\Exceptions
Definition: Core/REST/Common/Exceptions/ForbiddenException.php:7
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+.