Complex classes like ContentService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ContentService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class ContentService implements APIContentService, Sessionable |
||
| 32 | { |
||
| 33 | /** @var \eZ\Publish\Core\REST\Client\HttpClient */ |
||
| 34 | private $client; |
||
| 35 | |||
| 36 | /** @var \eZ\Publish\Core\REST\Common\Input\Dispatcher */ |
||
| 37 | private $inputDispatcher; |
||
| 38 | |||
| 39 | /** @var \eZ\Publish\Core\REST\Common\Output\Visitor */ |
||
| 40 | private $outputVisitor; |
||
| 41 | |||
| 42 | /** @var \eZ\Publish\Core\REST\Common\RequestParser */ |
||
| 43 | private $requestParser; |
||
| 44 | |||
| 45 | /** @var \eZ\Publish\Core\REST\Client\ContentTypeService */ |
||
| 46 | private $contentTypeService; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param \eZ\Publish\Core\REST\Client\HttpClient $client |
||
| 50 | * @param \eZ\Publish\Core\REST\Common\Input\Dispatcher $inputDispatcher |
||
| 51 | * @param \eZ\Publish\Core\REST\Common\Output\Visitor $outputVisitor |
||
| 52 | * @param \eZ\Publish\Core\REST\Common\RequestParser $requestParser |
||
| 53 | * @param \eZ\Publish\Core\REST\Client\ContentTypeService $contentTypeService |
||
| 54 | */ |
||
| 55 | public function __construct(HttpClient $client, Dispatcher $inputDispatcher, Visitor $outputVisitor, RequestParser $requestParser, ContentTypeService $contentTypeService) |
||
| 56 | { |
||
| 57 | $this->client = $client; |
||
| 58 | $this->inputDispatcher = $inputDispatcher; |
||
| 59 | $this->outputVisitor = $outputVisitor; |
||
| 60 | $this->requestParser = $requestParser; |
||
| 61 | $this->contentTypeService = $contentTypeService; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Set session ID. |
||
| 66 | * |
||
| 67 | * Only for testing |
||
| 68 | * |
||
| 69 | * @param mixed $id |
||
| 70 | * |
||
| 71 | * @private |
||
| 72 | */ |
||
| 73 | public function setSession($id) |
||
| 74 | { |
||
| 75 | if ($this->outputVisitor instanceof Sessionable) { |
||
| 76 | $this->outputVisitor->setSession($id); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Loads a content info object. |
||
| 82 | * |
||
| 83 | * To load fields use loadContent |
||
| 84 | * |
||
| 85 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 86 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 87 | * |
||
| 88 | * @param int $contentId |
||
| 89 | * |
||
| 90 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 91 | */ |
||
| 92 | public function loadContentInfo($contentId) |
||
| 93 | { |
||
| 94 | $response = $this->client->request( |
||
| 95 | 'GET', |
||
| 96 | $contentId, |
||
| 97 | new Message( |
||
| 98 | array('Accept' => $this->outputVisitor->getMediaType('ContentInfo')) |
||
| 99 | ) |
||
| 100 | ); |
||
| 101 | |||
| 102 | $restContentInfo = $this->inputDispatcher->parse($response); |
||
| 103 | |||
| 104 | return $this->completeContentInfo($restContentInfo); |
||
|
|
|||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * {@inheritdoc} |
||
| 109 | */ |
||
| 110 | public function loadContentInfoList(array $contentIds): iterable |
||
| 111 | { |
||
| 112 | throw new \Exception('@todo: Implement.'); |
||
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Loads a content info object for the given remoteId. |
||
| 117 | * |
||
| 118 | * To load fields use loadContent |
||
| 119 | * |
||
| 120 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
| 121 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist |
||
| 122 | * |
||
| 123 | * @param string $remoteId |
||
| 124 | * |
||
| 125 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 126 | */ |
||
| 127 | public function loadContentInfoByRemoteId($remoteId) |
||
| 128 | { |
||
| 129 | $response = $this->client->request( |
||
| 130 | 'GET', |
||
| 131 | $this->requestParser->generate('objectByRemote', array('object' => $remoteId)), |
||
| 132 | new Message( |
||
| 133 | array('Accept' => $this->outputVisitor->getMediaType('ContentInfo')) |
||
| 134 | ) |
||
| 135 | ); |
||
| 136 | |||
| 137 | if ($response->statusCode == 307) { |
||
| 138 | $response = $this->client->request( |
||
| 139 | 'GET', |
||
| 140 | $response->headers['Location'], |
||
| 141 | new Message( |
||
| 142 | array('Accept' => $this->outputVisitor->getMediaType('ContentInfo')) |
||
| 143 | ) |
||
| 144 | ); |
||
| 145 | } |
||
| 146 | |||
| 147 | $restContentInfo = $this->inputDispatcher->parse($response); |
||
| 148 | |||
| 149 | return $this->completeContentInfo($restContentInfo); |
||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Returns a complete ContentInfo based on $restContentInfo. |
||
| 154 | * |
||
| 155 | * @param \eZ\Publish\Core\REST\Client\Values\RestContentInfo $restContentInfo |
||
| 156 | * |
||
| 157 | * @return \eZ\Publish\Core\REST\Client\Values\Content\ContentInfo |
||
| 158 | */ |
||
| 159 | protected function completeContentInfo(Values\RestContentInfo $restContentInfo) |
||
| 160 | { |
||
| 161 | $versionUrlValues = $this->requestParser->parse( |
||
| 162 | 'objectVersion', |
||
| 163 | $this->fetchCurrentVersionUrl($restContentInfo->currentVersionReference) |
||
| 164 | ); |
||
| 165 | |||
| 166 | return new Values\Content\ContentInfo( |
||
| 167 | $this->contentTypeService, |
||
| 168 | array( |
||
| 169 | 'id' => $restContentInfo->id, |
||
| 170 | 'name' => $restContentInfo->name, |
||
| 171 | 'contentTypeId' => $restContentInfo->contentTypeId, |
||
| 172 | 'ownerId' => $restContentInfo->ownerId, |
||
| 173 | 'modificationDate' => $restContentInfo->modificationDate, |
||
| 174 | 'publishedDate' => $restContentInfo->publishedDate, |
||
| 175 | 'published' => $restContentInfo->published, |
||
| 176 | 'alwaysAvailable' => $restContentInfo->alwaysAvailable, |
||
| 177 | 'remoteId' => $restContentInfo->remoteId, |
||
| 178 | 'mainLanguageCode' => $restContentInfo->mainLanguageCode, |
||
| 179 | 'mainLocationId' => $restContentInfo->mainLocationId, |
||
| 180 | 'sectionId' => $restContentInfo->sectionId, |
||
| 181 | |||
| 182 | 'currentVersionNo' => $versionUrlValues['version'], |
||
| 183 | ) |
||
| 184 | ); |
||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Returns the URL of the current version referenced by |
||
| 189 | * $currentVersionReference. |
||
| 190 | * |
||
| 191 | * @param string $currentVersionReference |
||
| 192 | * |
||
| 193 | * @return string |
||
| 194 | */ |
||
| 195 | protected function fetchCurrentVersionUrl($currentVersionReference) |
||
| 196 | { |
||
| 197 | $versionResponse = $this->client->request( |
||
| 198 | 'GET', |
||
| 199 | $currentVersionReference |
||
| 200 | ); |
||
| 201 | |||
| 202 | if ($this->isErrorResponse($versionResponse)) { |
||
| 203 | return $this->inputDispatcher->parse($versionResponse); |
||
| 204 | } |
||
| 205 | |||
| 206 | return $versionResponse->headers['Location']; |
||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Checks if the given response is an error. |
||
| 211 | * |
||
| 212 | * @param Message $response |
||
| 213 | * |
||
| 214 | * @return bool |
||
| 215 | */ |
||
| 216 | protected function isErrorResponse(Message $response) |
||
| 217 | { |
||
| 218 | return strpos($response->headers['Content-Type'], 'application/vnd.ez.api.ErrorMessage') === 0; |
||
| 219 | } |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Loads a version info of the given content object. |
||
| 223 | * |
||
| 224 | * If no version number is given, the method returns the current version |
||
| 225 | * |
||
| 226 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 227 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 228 | * |
||
| 229 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 230 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 231 | * |
||
| 232 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 233 | */ |
||
| 234 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null) |
||
| 235 | { |
||
| 236 | throw new \Exception('@todo: Implement.'); |
||
| 237 | } |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Loads a version info of the given content object id. |
||
| 241 | * |
||
| 242 | * If no version number is given, the method returns the current version |
||
| 243 | * |
||
| 244 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 245 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 246 | * |
||
| 247 | * @param mixed $contentId |
||
| 248 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 249 | * |
||
| 250 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 251 | */ |
||
| 252 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
| 253 | { |
||
| 254 | throw new \Exception('@todo: Implement.'); |
||
| 255 | } |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Loads content in a version for the given content info object. |
||
| 259 | * |
||
| 260 | * If no version number is given, the method returns the current version |
||
| 261 | * |
||
| 262 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist |
||
| 263 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 264 | * |
||
| 265 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 266 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 267 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 268 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 269 | * |
||
| 270 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 271 | */ |
||
| 272 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 273 | { |
||
| 274 | return $this->loadContent( |
||
| 275 | $contentInfo->id, |
||
| 276 | $languages, |
||
| 277 | $versionNo |
||
| 278 | ); |
||
| 279 | } |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Loads content in the version given by version info. |
||
| 283 | * |
||
| 284 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 285 | * |
||
| 286 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 287 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 288 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 289 | * |
||
| 290 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 291 | */ |
||
| 292 | public function loadContentByVersionInfo(VersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
| 293 | { |
||
| 294 | $contentInfo = $versionInfo->getContentInfo(); |
||
| 295 | |||
| 296 | return $this->loadContent($contentInfo->id, $languages, $versionInfo->versionNo); |
||
| 297 | } |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Loads content in a version of the given content object. |
||
| 301 | * |
||
| 302 | * If no version number is given, the method returns the current version |
||
| 303 | * |
||
| 304 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given id does not exist |
||
| 305 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 306 | * |
||
| 307 | * @param int $contentId |
||
| 308 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 309 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 310 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 311 | * |
||
| 312 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 313 | * |
||
| 314 | * @todo Handle $versionNo = null |
||
| 315 | * @todo Handle language filters |
||
| 316 | */ |
||
| 317 | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 318 | { |
||
| 319 | // $contentId should already be a URL! |
||
| 320 | $contentIdValues = $this->requestParser->parse('object', $contentId); |
||
| 321 | |||
| 322 | $url = ''; |
||
| 323 | if ($versionNo === null) { |
||
| 324 | $url = $this->fetchCurrentVersionUrl( |
||
| 325 | $this->requestParser->generate( |
||
| 326 | 'objectCurrentVersion', |
||
| 327 | array( |
||
| 328 | 'object' => $contentIdValues['object'], |
||
| 329 | ) |
||
| 330 | ) |
||
| 331 | ); |
||
| 332 | } else { |
||
| 333 | $url = $this->requestParser->generate( |
||
| 334 | 'objectVersion', |
||
| 335 | array( |
||
| 336 | 'object' => $contentIdValues['object'], |
||
| 337 | 'version' => $versionNo, |
||
| 338 | ) |
||
| 339 | ); |
||
| 340 | } |
||
| 341 | |||
| 342 | $response = $this->client->request( |
||
| 343 | 'GET', |
||
| 344 | $url, |
||
| 345 | new Message( |
||
| 346 | array('Accept' => $this->outputVisitor->getMediaType('Version')) |
||
| 347 | ) |
||
| 348 | ); |
||
| 349 | |||
| 350 | return $this->inputDispatcher->parse($response); |
||
| 351 | } |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Loads content in a version for the content object reference by the given remote id. |
||
| 355 | * |
||
| 356 | * If no version is given, the method returns the current version |
||
| 357 | * |
||
| 358 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
| 359 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 360 | * |
||
| 361 | * @param string $remoteId |
||
| 362 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 363 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 364 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 365 | * |
||
| 366 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 367 | */ |
||
| 368 | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 369 | { |
||
| 370 | $contentInfo = $this->loadContentInfoByRemoteId($remoteId); |
||
| 371 | |||
| 372 | return $this->loadContentByContentInfo($contentInfo, $languages, $versionNo); |
||
| 373 | } |
||
| 374 | |||
| 375 | /** |
||
| 376 | * Creates a new content draft assigned to the authenticated user. |
||
| 377 | * |
||
| 378 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
| 379 | * but this required special rights for the authenticated user |
||
| 380 | * (this is useful for content staging where the transfer process does not |
||
| 381 | * have to authenticate with the user which created the content object in the source server). |
||
| 382 | * The user has to publish the draft if it should be visible. |
||
| 383 | * In 4.x at least one location has to be provided in the location creation array. |
||
| 384 | * |
||
| 385 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
| 386 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is a provided remoteId which exists in the system |
||
| 387 | * or there is no location provided (4.x) or multiple locations |
||
| 388 | * are under the same parent or if the a field value is not accepted by the field type |
||
| 389 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid |
||
| 390 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing |
||
| 391 | * |
||
| 392 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 393 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
| 394 | * |
||
| 395 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 396 | */ |
||
| 397 | public function createContent(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array()) |
||
| 398 | { |
||
| 399 | throw new \Exception('@todo: Implement.'); |
||
| 400 | } |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Updates the metadata. |
||
| 404 | * |
||
| 405 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
| 406 | * |
||
| 407 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
| 408 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
| 409 | * |
||
| 410 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 411 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
| 412 | * |
||
| 413 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
| 414 | */ |
||
| 415 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
| 416 | { |
||
| 417 | throw new \Exception('@todo: Implement.'); |
||
| 418 | } |
||
| 419 | |||
| 420 | /** |
||
| 421 | * Deletes a content object including all its versions and locations including their subtrees. |
||
| 422 | * |
||
| 423 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to delete the content (in one of the locations of the given content object) |
||
| 424 | * |
||
| 425 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 426 | */ |
||
| 427 | public function deleteContent(ContentInfo $contentInfo) |
||
| 428 | { |
||
| 429 | throw new \Exception('@todo: Implement.'); |
||
| 430 | } |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Creates a draft from a published or archived version. |
||
| 434 | * |
||
| 435 | * If no version is given, the current published version is used. |
||
| 436 | * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
| 437 | * It can be changed on updating the version. |
||
| 438 | * |
||
| 439 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the draft |
||
| 440 | * |
||
| 441 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 442 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 443 | * @param \eZ\Publish\API\Repository\Values\User\User $user if set given user is used to create the draft - otherwise the current user is used |
||
| 444 | * |
||
| 445 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 446 | */ |
||
| 447 | public function createContentDraft(ContentInfo $contentInfo, VersionInfo $versionInfo = null, User $user = null) |
||
| 448 | { |
||
| 449 | throw new \Exception('@todo: Implement.'); |
||
| 450 | } |
||
| 451 | |||
| 452 | /** |
||
| 453 | * Loads drafts for a user. |
||
| 454 | * |
||
| 455 | * If no user is given the drafts for the authenticated user a returned |
||
| 456 | * |
||
| 457 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load the draft list |
||
| 458 | * |
||
| 459 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
| 460 | * |
||
| 461 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo the drafts ({@link VersionInfo}) owned by the given user |
||
| 462 | */ |
||
| 463 | public function loadContentDrafts(User $user = null) |
||
| 464 | { |
||
| 465 | throw new \Exception('@todo: Implement.'); |
||
| 466 | } |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Updates the fields of a draft. |
||
| 470 | * |
||
| 471 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 472 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 473 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentUpdateStruct is not valid |
||
| 474 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value |
||
| 475 | * |
||
| 476 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 477 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 478 | * |
||
| 479 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
| 480 | */ |
||
| 481 | public function updateContent(VersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct) |
||
| 482 | { |
||
| 483 | throw new \Exception('@todo: Implement.'); |
||
| 484 | } |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Publishes a content version. |
||
| 488 | * |
||
| 489 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 490 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 491 | * |
||
| 492 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 493 | * @param string[] $translations |
||
| 494 | * |
||
| 495 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 496 | * |
||
| 497 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 498 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 499 | */ |
||
| 500 | public function publishVersion(VersionInfo $versionInfo, array $translations = Language::ALL) |
||
| 501 | { |
||
| 502 | throw new \Exception('@todo: Implement.'); |
||
| 503 | } |
||
| 504 | |||
| 505 | /** |
||
| 506 | * Removes the given version. |
||
| 507 | * |
||
| 508 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
| 509 | * published state or is a last version of the Content |
||
| 510 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
| 511 | * |
||
| 512 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 513 | */ |
||
| 514 | public function deleteVersion(VersionInfo $versionInfo) |
||
| 518 | |||
| 519 | /** |
||
| 520 | * Loads all versions for the given content. |
||
| 521 | * |
||
| 522 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
| 523 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the given status is invalid |
||
| 524 | * |
||
| 525 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 526 | * @param int|null $status |
||
| 527 | * |
||
| 528 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
| 529 | */ |
||
| 530 | public function loadVersions(ContentInfo $contentInfo, ?int $status = null) |
||
| 531 | { |
||
| 532 | throw new \Exception('@todo: Implement.'); |
||
| 533 | } |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Copies the content to a new location. If no version is given, |
||
| 537 | * all versions are copied, otherwise only the given version. |
||
| 538 | * |
||
| 539 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
| 540 | * |
||
| 541 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 542 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
| 543 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 544 | * |
||
| 545 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 546 | */ |
||
| 547 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, VersionInfo $versionInfo = null) |
||
| 548 | { |
||
| 549 | throw new \Exception('@todo: Implement.'); |
||
| 550 | } |
||
| 551 | |||
| 552 | /** |
||
| 553 | * Finds content objects for the given query. |
||
| 554 | * |
||
| 555 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
| 556 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
| 557 | * Currently supported: <code>array("languages" => array(<language1>,..))</code>. |
||
| 558 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
| 559 | * |
||
| 560 | * @return \eZ\Publish\API\Repository\Values\Content\SearchResult |
||
| 561 | */ |
||
| 562 | public function findContent(Query $query, array $languageFilter, $filterOnUserPermissions = true) |
||
| 563 | { |
||
| 564 | throw new \Exception('@todo: Implement.'); |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Performs a query for a single content object. |
||
| 569 | * |
||
| 570 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the object was not found by the query or due to permissions |
||
| 571 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the query would return more than one result |
||
| 572 | * |
||
| 573 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
| 574 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
| 575 | * Currently supported: <code>array("languages" => array(<language1>,..))</code>. |
||
| 576 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
| 577 | * |
||
| 578 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 579 | */ |
||
| 580 | public function findSingle(Query $query, array $languageFilter, $filterOnUserPermissions = true) |
||
| 581 | { |
||
| 582 | throw new \Exception('@todo: Implement.'); |
||
| 583 | } |
||
| 584 | |||
| 585 | /** |
||
| 586 | * Loads all outgoing relations for the given version. |
||
| 587 | * |
||
| 588 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 589 | * |
||
| 590 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 591 | * |
||
| 592 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 593 | */ |
||
| 594 | public function loadRelations(VersionInfo $versionInfo) |
||
| 595 | { |
||
| 596 | throw new \Exception('@todo: Implement.'); |
||
| 597 | } |
||
| 598 | |||
| 599 | /** |
||
| 600 | * Loads all incoming relations for a content object. |
||
| 601 | * |
||
| 602 | * The relations come only |
||
| 603 | * from published versions of the source content objects |
||
| 604 | * |
||
| 605 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 606 | * |
||
| 607 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 608 | * |
||
| 609 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 610 | */ |
||
| 611 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
| 612 | { |
||
| 613 | throw new \Exception('@todo: Implement.'); |
||
| 614 | } |
||
| 615 | |||
| 616 | /** |
||
| 617 | * Adds a relation of type common. |
||
| 618 | * |
||
| 619 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
| 620 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 621 | * |
||
| 622 | * The source of the relation is the content and version |
||
| 623 | * referenced by $versionInfo. |
||
| 624 | * |
||
| 625 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 626 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
| 627 | * |
||
| 628 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
| 629 | */ |
||
| 630 | public function addRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 631 | { |
||
| 632 | throw new \Exception('@todo: Implement.'); |
||
| 633 | } |
||
| 634 | |||
| 635 | /** |
||
| 636 | * Removes a relation of type COMMON from a draft. |
||
| 637 | * |
||
| 638 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
| 639 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 640 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
| 641 | * |
||
| 642 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 643 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
| 644 | */ |
||
| 645 | public function deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 646 | { |
||
| 647 | throw new \Exception('@todo: Implement.'); |
||
| 648 | } |
||
| 649 | |||
| 650 | /** |
||
| 651 | * Instantiates a new content create struct object. |
||
| 652 | * |
||
| 653 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable |
||
| 654 | * |
||
| 655 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 656 | * @param string $mainLanguageCode |
||
| 657 | * |
||
| 658 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 659 | */ |
||
| 660 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 664 | |||
| 665 | /** |
||
| 666 | * Instantiates a new content meta data update struct. |
||
| 667 | * |
||
| 668 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
| 669 | */ |
||
| 670 | public function newContentMetadataUpdateStruct() |
||
| 674 | |||
| 675 | /** |
||
| 676 | * Instantiates a new content update struct. |
||
| 677 | * |
||
| 678 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
| 679 | */ |
||
| 680 | public function newContentUpdateStruct() |
||
| 684 | |||
| 685 | // Ignore this eZ Publish 5 feature by now. |
||
| 686 | |||
| 687 | // @codeCoverageIgnoreStart |
||
| 688 | |||
| 689 | /** |
||
| 690 | * {@inheritdoc} |
||
| 691 | */ |
||
| 692 | public function removeTranslation(ContentInfo $contentInfo, $languageCode) |
||
| 693 | { |
||
| 694 | throw new \Exception('@todo: Implement.'); |
||
| 695 | } |
||
| 696 | |||
| 697 | /** |
||
| 698 | * {@inheritdoc} |
||
| 699 | */ |
||
| 700 | public function deleteTranslation(ContentInfo $contentInfo, $languageCode) |
||
| 701 | { |
||
| 702 | throw new \Exception('@todo: Implement.'); |
||
| 703 | } |
||
| 704 | |||
| 705 | /** |
||
| 706 | * {@inheritdoc} |
||
| 707 | */ |
||
| 708 | public function deleteTranslationFromDraft(VersionInfo $versionInfo, $languageCode) |
||
| 709 | { |
||
| 710 | throw new \Exception('@todo: Implement.'); |
||
| 711 | } |
||
| 712 | |||
| 713 | /** |
||
| 714 | * Bulk-load Content items by the list of ContentInfo Value Objects. |
||
| 715 | * |
||
| 716 | * Note: it does not throw exceptions on load, just ignores erroneous Content item. |
||
| 717 | * |
||
| 718 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList |
||
| 719 | * @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on |
||
| 720 | * returned value object. If not given all languages are returned. |
||
| 721 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true, |
||
| 722 | * unless all languages have been asked for. |
||
| 723 | * |
||
| 724 | * @throws \Exception Not implemented |
||
| 725 | */ |
||
| 726 | public function loadContentListByContentInfo(array $contentInfoList, array $languages = [], $useAlwaysAvailable = true) |
||
| 730 | |||
| 731 | /** |
||
| 732 | * Hides Content by making all the Locations appear hidden. |
||
| 733 | * It does not persist hidden state on Location object itself. |
||
| 734 | * |
||
| 735 | * Content hidden by this API can be revealed by revealContent API. |
||
| 736 | * |
||
| 737 | * @see revealContent |
||
| 738 | * |
||
| 739 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 740 | */ |
||
| 741 | public function hideContent(ContentInfo $contentInfo): void |
||
| 745 | |||
| 746 | /** |
||
| 747 | * Reveals Content hidden by hideContent API. |
||
| 748 | * Locations which were hidden before hiding Content will remain hidden. |
||
| 749 | * |
||
| 750 | * @see hideContent |
||
| 751 | * |
||
| 752 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 753 | */ |
||
| 754 | public function revealContent(ContentInfo $contentInfo): void |
||
| 758 | } |
||
| 759 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.