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

Core/REST/Client/TrashService.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\TrashService as APITrashService;
10 use eZ\Publish\API\Repository\Values\Content\Query;
11 use eZ\Publish\API\Repository\Values\Content\Location;
12 use eZ\Publish\API\Repository\Values\Content\Trash\SearchResult;
13 use eZ\Publish\API\Repository\Values\Content\TrashItem as APITrashItem;
14 use eZ\Publish\Core\Repository\Values\Content\TrashItem;
15 use eZ\Publish\Core\REST\Common\RequestParser;
16 use eZ\Publish\Core\REST\Common\Input\Dispatcher;
17 use eZ\Publish\Core\REST\Common\Output\Visitor;
18 use eZ\Publish\Core\REST\Common\Message;
19
23 class TrashService implements APITrashService, Sessionable
24 {
26 private $locationService;
27
29 private $client;
30
32 private $inputDispatcher;
33
35 private $outputVisitor;
36
38 private $requestParser;
39
47 public function __construct(LocationService $locationService, HttpClient $client, Dispatcher $inputDispatcher, Visitor $outputVisitor, RequestParser $requestParser)
48 {
49 $this->locationService = $locationService;
50 $this->client = $client;
51 $this->inputDispatcher = $inputDispatcher;
52 $this->outputVisitor = $outputVisitor;
53 $this->requestParser = $requestParser;
54 }
55
63 public function setSession($id)
64 {
65 if ($this->outputVisitor instanceof Sessionable) {
66 $this->outputVisitor->setSession($id);
67 }
68 }
69
82 public function loadTrashItem($trashItemId)
83 {
84 $response = $this->client->request(
85 'GET',
86 $trashItemId,
87 new Message(
88 array('Accept' => $this->outputVisitor->getMediaType('Location'))
89 )
90 );
91
92 $location = $this->inputDispatcher->parse($response);
93
94 return $this->buildTrashItem($location);
95 }
96
109 public function trash(Location $location)
110 {
111 throw new \Exception('@todo: Implement.');
112 }
113
126 public function recover(APITrashItem $trashItem, Location $newParentLocation = null)
127 {
128 throw new \Exception('@todo: Implement.');
129 }
130
139 public function emptyTrash()
140 {
141 $response = $this->client->request(
142 'DELETE',
143 $this->requestParser->generate('trashItems'),
144 new Message(
145 // @todo: What media-type should we set here? Actually, it should be
146 // all expected exceptions + none? Or is "Location" correct,
147 // since this is what is to be expected by the resource
148 // identified by the URL?
149 array('Accept' => $this->outputVisitor->getMediaType('Location'))
150 )
151 );
152
153 if (!empty($response->body)) {
154 $this->inputDispatcher->parse($response);
155 }
156 }
157
167 public function deleteTrashItem(APITrashItem $trashItem)
168 {
169 $response = $this->client->request(
170 'DELETE',
171 $trashItem->id,
172 new Message(
173 // @todo: What media-type should we set here? Actually, it should be
174 // all expected exceptions + none? Or is "Location" correct,
175 // since this is what is to be expected by the resource
176 // identified by the URL?
177 array('Accept' => $this->outputVisitor->getMediaType('Location'))
178 )
179 );
180
181 if (!empty($response->body)) {
182 $this->inputDispatcher->parse($response);
183 }
184 }
185
195 public function findTrashItems(Query $query)
196 {
197 $response = $this->client->request(
198 'GET',
199 $this->requestParser->generate('trashItems'),
200 new Message(
201 array('Accept' => $this->outputVisitor->getMediaType('LocationList'))
202 )
203 );
204
205 $locations = $this->inputDispatcher->parse($response);
206
207 $trashItems = array();
208 foreach ($locations as $location) {
209 $trashItems[] = $this->buildTrashItem($location);
210 }
211
212
213 return new SearchResult([
214 'items' => $trashItems,
215 'totalCount' => count($trashItems),
216 ]);
217 }
218
226 protected function buildTrashItem(Location $location)
227 {
228 return new TrashItem(
229 array(
230 'contentInfo' => $location->contentInfo,
231 'id' => $location->id,
232 'priority' => $location->priority,
233 'hidden' => $location->hidden,
234 'invisible' => $location->invisible,
235 'remoteId' => $location->remoteId,
236 'parentLocationId' => $location->parentLocationId,
237 'pathString' => $location->pathString,
238 'depth' => (int)$location->depth,
239 'sortField' => $location->sortField,
240 'sortOrder' => $location->sortOrder,
241 )
242 );
243 }
244 }
eZ\Publish\API\Repository\Values\Content\Location
Definition: API/Repository/Values/Content/Location.php:32
eZ\Publish\API\Repository\Values\Content\Query
This class is used to perform a Content query.
Definition: API/Repository/Values/Content/Query.php:15
eZ\Publish\API\Repository\Values\Content\TrashItem
this class represents a trash item, which is actually a trashed location.
Definition: API/Repository/Values/Content/TrashItem.php:13
eZ\Publish\API\Repository\Values\Content\Trash\SearchResult
Definition: Content/Trash/SearchResult.php:13
eZ\Publish\Core\REST\Client\LocationService
Definition: Core/REST/Client/LocationService.php:27
eZ\Publish\Core\REST\Client\TrashService
Trash service used for content/location trash handling.
Definition: Core/REST/Client/TrashService.php:24
eZ\Publish\Core\REST\Client\TrashService\emptyTrash
emptyTrash()
Empties trash.
Definition: Core/REST/Client/TrashService.php:139
eZ\Publish\Core\REST\Client\TrashService\$requestParser
$requestParser
Definition: Core/REST/Client/TrashService.php:38
eZ\Publish\Core\REST\Client\TrashService\deleteTrashItem
deleteTrashItem(APITrashItem $trashItem)
Deletes a trash item.
Definition: Core/REST/Client/TrashService.php:167
eZ\Publish\Core\REST\Client\TrashService\$inputDispatcher
$inputDispatcher
Definition: Core/REST/Client/TrashService.php:32
eZ\Publish\Core\REST\Client\TrashService\buildTrashItem
buildTrashItem(Location $location)
Converts the Location value object to TrashItem value object.
Definition: Core/REST/Client/TrashService.php:226
eZ\Publish\Core\REST\Client\TrashService\trash
trash(Location $location)
Sends $location and all its children to trash and returns the corresponding trash item.
Definition: Core/REST/Client/TrashService.php:109
eZ\Publish\Core\REST\Client\TrashService\__construct
__construct(LocationService $locationService, HttpClient $client, Dispatcher $inputDispatcher, Visitor $outputVisitor, RequestParser $requestParser)
Definition: Core/REST/Client/TrashService.php:47
eZ\Publish\Core\REST\Client\TrashService\loadTrashItem
loadTrashItem($trashItemId)
Loads a trashed location object from its $id.
Definition: Core/REST/Client/TrashService.php:82
eZ\Publish\Core\REST\Client\TrashService\$client
$client
Definition: Core/REST/Client/TrashService.php:29
eZ\Publish\Core\REST\Client\TrashService\findTrashItems
findTrashItems(Query $query)
Returns a collection of Trashed locations contained in the trash, which are readable by the current u...
Definition: Core/REST/Client/TrashService.php:195
eZ\Publish\Core\REST\Client\TrashService\$locationService
$locationService
Definition: Core/REST/Client/TrashService.php:26
eZ\Publish\Core\REST\Client\TrashService\setSession
setSession($id)
Set session ID.
Definition: Core/REST/Client/TrashService.php:63
eZ\Publish\Core\REST\Client\TrashService\recover
recover(APITrashItem $trashItem, Location $newParentLocation=null)
Recovers the $trashedLocation at its original place if possible.
Definition: Core/REST/Client/TrashService.php:126
eZ\Publish\Core\REST\Client\TrashService\$outputVisitor
$outputVisitor
Definition: Core/REST/Client/TrashService.php:35
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\Repository\Values\Content\TrashItem
this class represents a trash item, which is actually a trashed location.
Definition: Core/Repository/Values/Content/TrashItem.php:17
eZ\Publish\API\Repository\TrashService
Trash service, used for managing trashed content.
Definition: API/Repository/TrashService.php:17
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+.