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

Core/REST/Client/SectionService.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Client;
8
9 use eZ\Publish\API\Repository\SectionService as APISectionService;
10 use eZ\Publish\API\Repository\Values\Content\ContentInfo;
11 use eZ\Publish\API\Repository\Values\Content\Section;
12 use eZ\Publish\API\Repository\Values\Content\SectionCreateStruct;
13 use eZ\Publish\API\Repository\Values\Content\SectionUpdateStruct;
14 use eZ\Publish\Core\REST\Common\Exceptions\InvalidArgumentException;
15 use eZ\Publish\Core\REST\Common\Exceptions\ForbiddenException;
16 use eZ\Publish\Core\REST\Common\RequestParser;
17 use eZ\Publish\Core\REST\Common\Input\Dispatcher;
18 use eZ\Publish\Core\REST\Common\Output\Visitor;
19 use eZ\Publish\Core\REST\Common\Message;
20 use eZ\Publish\Core\REST\Common\Values\RestContentMetadataUpdateStruct;
21
28 class SectionService implements APISectionService, Sessionable
29 {
31 private $client;
32
34 private $inputDispatcher;
35
37 private $outputVisitor;
38
40 private $requestParser;
41
48 public function __construct(HttpClient $client, Dispatcher $inputDispatcher, Visitor $outputVisitor, RequestParser $requestParser)
49 {
50 $this->client = $client;
51 $this->inputDispatcher = $inputDispatcher;
52 $this->outputVisitor = $outputVisitor;
53 $this->requestParser = $requestParser;
54 }
55
65 public function setSession($id)
66 {
67 if ($this->client instanceof Sessionable) {
68 $this->client->setSession($id);
69 }
70 }
71
82 public function createSection(SectionCreateStruct $sectionCreateStruct)
83 {
84 $inputMessage = $this->outputVisitor->visit($sectionCreateStruct);
85 $inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('Section');
86
87 $result = $this->client->request(
88 'POST',
89 $this->requestParser->generate('sections'),
90 $inputMessage
91 );
92
93 try {
94 return $this->inputDispatcher->parse($result);
95 } catch (ForbiddenException $e) {
96 throw new InvalidArgumentException($e->getMessage(), $e->getCode());
97 }
98 }
99
111 public function updateSection(Section $section, SectionUpdateStruct $sectionUpdateStruct)
112 {
113 $inputMessage = $this->outputVisitor->visit($sectionUpdateStruct);
114 $inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('Section');
115 $inputMessage->headers['X-HTTP-Method-Override'] = 'PATCH';
116
117 // Should originally be PATCH, but PHP's shiny new internal web server
118 // dies with it.
119 $result = $this->client->request(
120 'POST',
121 $section->id,
122 $inputMessage
123 );
124
125 try {
126 return $this->inputDispatcher->parse($result);
127 } catch (ForbiddenException $e) {
128 throw new InvalidArgumentException($e->getMessage(), $e->getCode());
129 }
130 }
131
142 public function loadSection($sectionId)
143 {
144 $response = $this->client->request(
145 'GET',
146 $sectionId,
147 new Message(
148 array('Accept' => $this->outputVisitor->getMediaType('Section'))
149 )
150 );
151
152 return $this->inputDispatcher->parse($response);
153 }
154
160 public function loadSections()
161 {
162 $response = $this->client->request(
163 'GET',
164 $this->requestParser->generate('sections'),
165 new Message(
166 array('Accept' => $this->outputVisitor->getMediaType('SectionList'))
167 )
168 );
169
170 return $this->inputDispatcher->parse($response);
171 }
172
183 public function loadSectionByIdentifier($sectionIdentifier)
184 {
185 $response = $this->client->request(
186 'GET',
187 $this->requestParser->generate('sectionByIdentifier', array('section' => $sectionIdentifier)),
188 new Message(
189 array('Accept' => $this->outputVisitor->getMediaType('SectionList'))
190 )
191 );
192 $result = $this->inputDispatcher->parse($response);
193
194 return reset($result);
195 }
196
206 public function countAssignedContents(Section $section)
207 {
208 throw new \Exception('@todo: Implement.');
209 }
210
222 public function isSectionUsed(Section $section)
223 {
224 throw new \Exception('@todo: Implement.');
225 }
226
240 public function assignSection(ContentInfo $contentInfo, Section $section)
241 {
242 $inputMessage = $this->outputVisitor->visit(
243 new RestContentMetadataUpdateStruct(
244 array('sectionId' => $section->id)
245 )
246 );
247 $inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('Content');
248 $inputMessage->headers['X-HTTP-Method-Override'] = 'PATCH';
249
250 $this->client->request(
251 'POST',
252 $contentInfo->id,
253 $inputMessage
254 );
255
256 // Will throw exception on error, no return value for method
257 // @todo: Deactivated due to missing implementation of visitor for
258 // content on the server side.
259 // Should be: $result = $this->inputDispatcher->parse( $response );
260 }
261
272 public function deleteSection(Section $section)
273 {
274 $response = $this->client->request(
275 'DELETE',
276 $section->id,
277 new Message(
278 // @todo: What media-type should we set here? Actually, it should be
279 // all expected exceptions + none? Or is "Section" correct,
280 // since this is what is to be expected by the resource
281 // identified by the URL?
282 array('Accept' => $this->outputVisitor->getMediaType('Section'))
283 )
284 );
285
286 if (!empty($response->body)) {
287 $this->inputDispatcher->parse($response);
288 }
289 }
290
296 public function newSectionCreateStruct()
297 {
298 return new SectionCreateStruct();
299 }
300
306 public function newSectionUpdateStruct()
307 {
308 return new SectionUpdateStruct();
309 }
310 }
eZ\Publish\API\Repository\Values\Content\ContentInfo
Definition: API/Repository/Values/Content/ContentInfo.php:31
eZ\Publish\API\Repository\Values\Content\SectionCreateStruct
This class represents a section.
Definition: API/Repository/Values/Content/SectionCreateStruct.php:14
eZ\Publish\API\Repository\Values\Content\SectionUpdateStruct
This class is used to provide data for updating a section.
Definition: API/Repository/Values/Content/SectionUpdateStruct.php:13
eZ\Publish\API\Repository\Values\Content\Section
Definition: API/Repository/Values/Content/Section.php:19
eZ\Publish\Core\REST\Client\SectionService
Implementation of the \eZ\Publish\API\Repository\SectionService interface.
Definition: Core/REST/Client/SectionService.php:29
eZ\Publish\Core\REST\Client\SectionService\$inputDispatcher
$inputDispatcher
Definition: Core/REST/Client/SectionService.php:34
eZ\Publish\Core\REST\Client\SectionService\$outputVisitor
$outputVisitor
Definition: Core/REST/Client/SectionService.php:37
eZ\Publish\Core\REST\Client\SectionService\newSectionUpdateStruct
newSectionUpdateStruct()
Instantiates a new SectionUpdateStruct.
Definition: Core/REST/Client/SectionService.php:306
eZ\Publish\Core\REST\Client\SectionService\isSectionUsed
isSectionUsed(Section $section)
Returns true if the given section is assigned to contents, or used in role policies,...
Definition: Core/REST/Client/SectionService.php:222
eZ\Publish\Core\REST\Client\SectionService\updateSection
updateSection(Section $section, SectionUpdateStruct $sectionUpdateStruct)
Updates the given in the content repository.
Definition: Core/REST/Client/SectionService.php:111
eZ\Publish\Core\REST\Client\SectionService\$client
$client
Definition: Core/REST/Client/SectionService.php:31
eZ\Publish\Core\REST\Client\SectionService\countAssignedContents
countAssignedContents(Section $section)
Counts the contents which $section is assigned to.
Definition: Core/REST/Client/SectionService.php:206
eZ\Publish\Core\REST\Client\SectionService\deleteSection
deleteSection(Section $section)
Deletes $section from content repository.
Definition: Core/REST/Client/SectionService.php:272
eZ\Publish\Core\REST\Client\SectionService\__construct
__construct(HttpClient $client, Dispatcher $inputDispatcher, Visitor $outputVisitor, RequestParser $requestParser)
Definition: Core/REST/Client/SectionService.php:48
eZ\Publish\Core\REST\Client\SectionService\setSession
setSession($id)
Set session ID.
Definition: Core/REST/Client/SectionService.php:65
eZ\Publish\Core\REST\Client\SectionService\assignSection
assignSection(ContentInfo $contentInfo, Section $section)
Assigns the content to the given section this method overrides the current assigned section.
Definition: Core/REST/Client/SectionService.php:240
eZ\Publish\Core\REST\Client\SectionService\createSection
createSection(SectionCreateStruct $sectionCreateStruct)
Creates the a new Section in the content repository.
Definition: Core/REST/Client/SectionService.php:82
eZ\Publish\Core\REST\Client\SectionService\newSectionCreateStruct
newSectionCreateStruct()
Instantiates a new SectionCreateStruct.
Definition: Core/REST/Client/SectionService.php:296
eZ\Publish\Core\REST\Client\SectionService\loadSections
loadSections()
Loads all sections, excluding the ones the current user is not allowed to read.
Definition: Core/REST/Client/SectionService.php:160
eZ\Publish\Core\REST\Client\SectionService\loadSectionByIdentifier
loadSectionByIdentifier($sectionIdentifier)
Loads a Section from its identifier ($sectionIdentifier).
Definition: Core/REST/Client/SectionService.php:183
eZ\Publish\Core\REST\Client\SectionService\loadSection
loadSection($sectionId)
Loads a Section from its id ($sectionId).
Definition: Core/REST/Client/SectionService.php:142
eZ\Publish\Core\REST\Client\SectionService\$requestParser
$requestParser
Definition: Core/REST/Client/SectionService.php:40
eZ\Publish\Core\REST\Common\Exceptions\ForbiddenException
Exception thrown if the request is forbidden.
Definition: Core/REST/Common/Exceptions/ForbiddenException.php:15
eZ\Publish\Core\REST\Common\Exceptions\InvalidArgumentException
This exception is thrown if a service method is called with an illegal or non appropriate value.
Definition: Core/REST/Common/Exceptions/InvalidArgumentException.php:15
eZ\Publish\Core\REST\Common\Input\Dispatcher
Input dispatcher.
Definition: Dispatcher.php:16
eZ\Publish\Core\REST\Common\Message
Simple response struct.
Definition: Core/REST/Common/Message.php:13
eZ\Publish\Core\REST\Common\Output\Visitor
Visits a value object into an HTTP Response.
Definition: Visitor.php:15
eZ\Publish\Core\REST\Common\Values\RestContentMetadataUpdateStruct
Extended ContentMetadataUpdateStruct that includes section information.
Definition: RestContentMetadataUpdateStruct.php:15
eZ\Publish\API\Repository\SectionService
Section service, used for section operations.
Definition: API/Repository/SectionService.php:19
eZ\Publish\Core\REST\Client\HttpClient
Interface for Http Client implementations.
Definition: REST/Client/HttpClient.php:15
eZ\Publish\Core\REST\Client\Sessionable
Implementation of the \eZ\Publish\API\Repository\SectionService interface.
Definition: Sessionable.php:16
eZ\Publish\Core\REST\Common\RequestParser
Interface for Request parsers.
Definition: RequestParser.php:13
eZ\Publish\Core\REST\Client
Definition: Core/REST/Client/ContentService.php:7
eZ\Publish\Core\REST\Common\RequestParser
Definition: EzPublish.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.