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

Core/REST/Server/Controller/URLAlias.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Server\Controller;
8
9 use eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException;
10 use eZ\Publish\API\Repository\Exceptions\InvalidArgumentException;
11 use eZ\Publish\Core\REST\Common\Message;
12 use eZ\Publish\Core\REST\Server\Values;
13 use eZ\Publish\Core\REST\Server\Controller as RestController;
14 use eZ\Publish\API\Repository\URLAliasService;
15 use eZ\Publish\API\Repository\LocationService;
16 use Symfony\Component\HttpFoundation\Request;
17
21 class URLAlias extends RestController
22 {
28 protected $urlAliasService;
29
35 protected $locationService;
36
43 public function __construct(URLAliasService $urlAliasService, LocationService $locationService)
44 {
45 $this->urlAliasService = $urlAliasService;
46 $this->locationService = $locationService;
47 }
48
56 public function loadURLAlias($urlAliasId)
57 {
58 return $this->urlAliasService->load($urlAliasId);
59 }
60
66 public function listGlobalURLAliases()
67 {
68 return new Values\URLAliasRefList(
69 $this->urlAliasService->listGlobalAliases(),
70 $this->router->generate('ezpublish_rest_listGlobalURLAliases')
71 );
72 }
73
81 public function listLocationURLAliases($locationPath, Request $request)
82 {
83 $locationPathParts = explode('/', $locationPath);
84
85 $location = $this->locationService->loadLocation(
86 array_pop($locationPathParts)
87 );
88
89 $custom = !($request->query->has('custom') && $request->query->get('custom') === 'false');
90
91 return new Values\CachedValue(
92 new Values\URLAliasRefList(
93 $this->urlAliasService->listLocationAliases($location, $custom),
94 $request->getPathInfo()
95 ),
96 ['locationId' => $location->id]
97 );
98 }
99
107 public function createURLAlias(Request $request)
108 {
109 $urlAliasCreate = $this->inputDispatcher->parse(
110 new Message(
111 ['Content-Type' => $request->headers->get('Content-Type')],
112 $request->getContent()
113 )
114 );
115
116 if ($urlAliasCreate['_type'] === 'LOCATION') {
117 $locationPathParts = explode(
118 '/',
119 $this->requestParser->parseHref($urlAliasCreate['location']['_href'], 'locationPath')
120 );
121
122 $location = $this->locationService->loadLocation(
123 array_pop($locationPathParts)
124 );
125
126 try {
127 $createdURLAlias = $this->urlAliasService->createUrlAlias(
128 $location,
129 $urlAliasCreate['path'],
130 $urlAliasCreate['languageCode'],
131 $urlAliasCreate['forward'],
132 $urlAliasCreate['alwaysAvailable']
133 );
134 } catch (InvalidArgumentException $e) {
135 throw new ForbiddenException($e->getMessage());
136 }
137 } else {
138 try {
139 $createdURLAlias = $this->urlAliasService->createGlobalUrlAlias(
140 $urlAliasCreate['resource'],
141 $urlAliasCreate['path'],
142 $urlAliasCreate['languageCode'],
143 $urlAliasCreate['forward'],
144 $urlAliasCreate['alwaysAvailable']
145 );
146 } catch (InvalidArgumentException $e) {
147 throw new ForbiddenException($e->getMessage());
148 }
149 }
150
151 return new Values\CreatedURLAlias(
152 [
153 'urlAlias' => $createdURLAlias,
154 ]
155 );
156 }
157
165 public function deleteURLAlias($urlAliasId)
166 {
167 $this->urlAliasService->removeAliases(
168 [
169 $this->urlAliasService->load($urlAliasId),
170 ]
171 );
172
173 return new Values\NoContent();
174 }
175 }
eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
This exception is thrown if a service method is called with an illegal or non appropriate value.
Definition: API/Repository/Exceptions/InvalidArgumentException.php:13
eZ\Publish\Core\Base\Exceptions\ForbiddenException
Forbidden Exception implementation.
Definition: Core/Base/Exceptions/ForbiddenException.php:17
eZ\Publish\Core\REST\Common\Message
Simple response struct.
Definition: Core/REST/Common/Message.php:13
eZ\Publish\Core\REST\Server\Controller\URLAlias
URLAlias controller.
Definition: Core/REST/Server/Controller/URLAlias.php:22
eZ\Publish\Core\REST\Server\Controller\URLAlias\listLocationURLAliases
listLocationURLAliases($locationPath, Request $request)
Returns the list of URL aliases for a location.
Definition: Core/REST/Server/Controller/URLAlias.php:81
eZ\Publish\Core\REST\Server\Controller\URLAlias\__construct
__construct(URLAliasService $urlAliasService, LocationService $locationService)
Construct controller.
Definition: Core/REST/Server/Controller/URLAlias.php:43
eZ\Publish\Core\REST\Server\Controller\URLAlias\createURLAlias
createURLAlias(Request $request)
Creates a new URL alias.
Definition: Core/REST/Server/Controller/URLAlias.php:107
eZ\Publish\Core\REST\Server\Controller\URLAlias\$locationService
$locationService
Definition: Core/REST/Server/Controller/URLAlias.php:35
eZ\Publish\Core\REST\Server\Controller\URLAlias\deleteURLAlias
deleteURLAlias($urlAliasId)
The given URL alias is deleted.
Definition: Core/REST/Server/Controller/URLAlias.php:165
eZ\Publish\Core\REST\Server\Controller\URLAlias\$urlAliasService
$urlAliasService
Definition: Core/REST/Server/Controller/URLAlias.php:28
eZ\Publish\Core\REST\Server\Controller\URLAlias\listGlobalURLAliases
listGlobalURLAliases()
Returns the list of global URL aliases.
Definition: Core/REST/Server/Controller/URLAlias.php:66
eZ\Publish\Core\REST\Server\Controller\URLAlias\loadURLAlias
loadURLAlias($urlAliasId)
Returns the URL alias with the given ID.
Definition: Core/REST/Server/Controller/URLAlias.php:56
eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
Exception thrown if the request is forbidden.
Definition: Core/REST/Server/Exceptions/ForbiddenException.php:15
eZ\Publish\Core\REST\Server\Values\CachedValue
Definition: Values/CachedValue.php:13
eZ\Publish\Core\REST\Server\Values\CreatedURLAlias
Struct representing a freshly created URLAlias.
Definition: Values/CreatedURLAlias.php:15
eZ\Publish\Core\REST\Server\Values\NoContent
Definition: Values/NoContent.php:12
eZ\Publish\Core\REST\Server\Values\URLAliasRefList
URLAlias ref list view model.
Definition: Values/URLAliasRefList.php:15
eZ\Publish\API\Repository\LocationService
Definition: API/Repository/LocationService.php:21
eZ\Publish\API\Repository\URLAliasService
Definition: API/Repository/URLAliasService.php:17
eZ\Publish\Core\REST\Server\Controller
Definition: BinaryContent.php:7
eZ\Publish\Core\REST\Server\Values
Definition: Core/REST/Server/Values/BookmarkList.php:9
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.