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 |
||
| 32 | class ContentService implements APIContentService, Sessionable |
||
| 33 | { |
||
| 34 | /** @var \eZ\Publish\Core\REST\Client\HttpClient */ |
||
| 35 | private $client; |
||
| 36 | |||
| 37 | /** @var \eZ\Publish\Core\REST\Common\Input\Dispatcher */ |
||
| 38 | private $inputDispatcher; |
||
| 39 | |||
| 40 | /** @var \eZ\Publish\Core\REST\Common\Output\Visitor */ |
||
| 41 | private $outputVisitor; |
||
| 42 | |||
| 43 | /** @var \eZ\Publish\Core\REST\Common\RequestParser */ |
||
| 44 | private $requestParser; |
||
| 45 | |||
| 46 | /** @var \eZ\Publish\Core\REST\Client\ContentTypeService */ |
||
| 47 | private $contentTypeService; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param \eZ\Publish\Core\REST\Client\HttpClient $client |
||
| 51 | * @param \eZ\Publish\Core\REST\Common\Input\Dispatcher $inputDispatcher |
||
| 52 | * @param \eZ\Publish\Core\REST\Common\Output\Visitor $outputVisitor |
||
| 53 | * @param \eZ\Publish\Core\REST\Common\RequestParser $requestParser |
||
| 54 | * @param \eZ\Publish\Core\REST\Client\ContentTypeService $contentTypeService |
||
| 55 | */ |
||
| 56 | public function __construct(HttpClient $client, Dispatcher $inputDispatcher, Visitor $outputVisitor, RequestParser $requestParser, ContentTypeService $contentTypeService) |
||
| 57 | { |
||
| 58 | $this->client = $client; |
||
| 59 | $this->inputDispatcher = $inputDispatcher; |
||
| 60 | $this->outputVisitor = $outputVisitor; |
||
| 61 | $this->requestParser = $requestParser; |
||
| 62 | $this->contentTypeService = $contentTypeService; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Set session ID. |
||
| 67 | * |
||
| 68 | * Only for testing |
||
| 69 | * |
||
| 70 | * @param mixed $id |
||
| 71 | * |
||
| 72 | * @private |
||
| 73 | */ |
||
| 74 | public function setSession($id) |
||
| 75 | { |
||
| 76 | if ($this->outputVisitor instanceof Sessionable) { |
||
| 77 | $this->outputVisitor->setSession($id); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Loads a content info object. |
||
| 83 | * |
||
| 84 | * To load fields use loadContent |
||
| 85 | * |
||
| 86 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 87 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 88 | * |
||
| 89 | * @param int $contentId |
||
| 90 | * |
||
| 91 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 92 | */ |
||
| 93 | public function loadContentInfo($contentId) |
||
| 94 | { |
||
| 95 | $response = $this->client->request( |
||
| 96 | 'GET', |
||
| 97 | $contentId, |
||
| 98 | new Message( |
||
| 99 | ['Accept' => $this->outputVisitor->getMediaType('ContentInfo')] |
||
| 100 | ) |
||
| 101 | ); |
||
| 102 | |||
| 103 | $restContentInfo = $this->inputDispatcher->parse($response); |
||
| 104 | |||
| 105 | return $this->completeContentInfo($restContentInfo); |
||
|
|
|||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * {@inheritdoc} |
||
| 110 | */ |
||
| 111 | public function loadContentInfoList(array $contentIds): iterable |
||
| 112 | { |
||
| 113 | throw new \Exception('@todo: Implement.'); |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Loads a content info object for the given remoteId. |
||
| 118 | * |
||
| 119 | * To load fields use loadContent |
||
| 120 | * |
||
| 121 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
| 122 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist |
||
| 123 | * |
||
| 124 | * @param string $remoteId |
||
| 125 | * |
||
| 126 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 127 | */ |
||
| 128 | public function loadContentInfoByRemoteId($remoteId) |
||
| 129 | { |
||
| 130 | $response = $this->client->request( |
||
| 131 | 'GET', |
||
| 132 | $this->requestParser->generate('objectByRemote', ['object' => $remoteId]), |
||
| 133 | new Message( |
||
| 134 | ['Accept' => $this->outputVisitor->getMediaType('ContentInfo')] |
||
| 135 | ) |
||
| 136 | ); |
||
| 137 | |||
| 138 | if ($response->statusCode == 307) { |
||
| 139 | $response = $this->client->request( |
||
| 140 | 'GET', |
||
| 141 | $response->headers['Location'], |
||
| 142 | new Message( |
||
| 143 | ['Accept' => $this->outputVisitor->getMediaType('ContentInfo')] |
||
| 144 | ) |
||
| 145 | ); |
||
| 146 | } |
||
| 147 | |||
| 148 | $restContentInfo = $this->inputDispatcher->parse($response); |
||
| 149 | |||
| 150 | return $this->completeContentInfo($restContentInfo); |
||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Returns a complete ContentInfo based on $restContentInfo. |
||
| 155 | * |
||
| 156 | * @param \eZ\Publish\Core\REST\Client\Values\RestContentInfo $restContentInfo |
||
| 157 | * |
||
| 158 | * @return \eZ\Publish\Core\REST\Client\Values\Content\ContentInfo |
||
| 159 | */ |
||
| 160 | protected function completeContentInfo(Values\RestContentInfo $restContentInfo) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Returns the URL of the current version referenced by |
||
| 190 | * $currentVersionReference. |
||
| 191 | * |
||
| 192 | * @param string $currentVersionReference |
||
| 193 | * |
||
| 194 | * @return string |
||
| 195 | */ |
||
| 196 | protected function fetchCurrentVersionUrl($currentVersionReference) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Checks if the given response is an error. |
||
| 212 | * |
||
| 213 | * @param Message $response |
||
| 214 | * |
||
| 215 | * @return bool |
||
| 216 | */ |
||
| 217 | protected function isErrorResponse(Message $response) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Loads a version info of the given content object. |
||
| 224 | * |
||
| 225 | * If no version number is given, the method returns the current version |
||
| 226 | * |
||
| 227 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 228 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 229 | * |
||
| 230 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 231 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 232 | * |
||
| 233 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 234 | */ |
||
| 235 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null) |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Loads a version info of the given content object id. |
||
| 242 | * |
||
| 243 | * If no version number is given, the method returns the current version |
||
| 244 | * |
||
| 245 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 246 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 247 | * |
||
| 248 | * @param mixed $contentId |
||
| 249 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 250 | * |
||
| 251 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 252 | */ |
||
| 253 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Loads content in a version for the given content info object. |
||
| 260 | * |
||
| 261 | * If no version number is given, the method returns the current version |
||
| 262 | * |
||
| 263 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist |
||
| 264 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 265 | * |
||
| 266 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 267 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 268 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 269 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 270 | * |
||
| 271 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 272 | */ |
||
| 273 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Loads content in the version given by version info. |
||
| 284 | * |
||
| 285 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 286 | * |
||
| 287 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 288 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 289 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 290 | * |
||
| 291 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 292 | */ |
||
| 293 | public function loadContentByVersionInfo(VersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Loads content in a version of the given content object. |
||
| 302 | * |
||
| 303 | * If no version number is given, the method returns the current version |
||
| 304 | * |
||
| 305 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given id does not exist |
||
| 306 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 307 | * |
||
| 308 | * @param int $contentId |
||
| 309 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 310 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 311 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 312 | * |
||
| 313 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 314 | * |
||
| 315 | * @todo Handle $versionNo = null |
||
| 316 | * @todo Handle language filters |
||
| 317 | */ |
||
| 318 | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Loads content in a version for the content object reference by the given remote id. |
||
| 356 | * |
||
| 357 | * If no version is given, the method returns the current version |
||
| 358 | * |
||
| 359 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
| 360 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 361 | * |
||
| 362 | * @param string $remoteId |
||
| 363 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 364 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 365 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 366 | * |
||
| 367 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 368 | */ |
||
| 369 | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Creates a new content draft assigned to the authenticated user. |
||
| 378 | * |
||
| 379 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
| 380 | * but this required special rights for the authenticated user |
||
| 381 | * (this is useful for content staging where the transfer process does not |
||
| 382 | * have to authenticate with the user which created the content object in the source server). |
||
| 383 | * The user has to publish the draft if it should be visible. |
||
| 384 | * In 4.x at least one location has to be provided in the location creation array. |
||
| 385 | * |
||
| 386 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
| 387 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is a provided remoteId which exists in the system |
||
| 388 | * or there is no location provided (4.x) or multiple locations |
||
| 389 | * are under the same parent or if the a field value is not accepted by the field type |
||
| 390 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid |
||
| 391 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing |
||
| 392 | * |
||
| 393 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 394 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
| 395 | * |
||
| 396 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 397 | */ |
||
| 398 | public function createContent(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = []) |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Updates the metadata. |
||
| 405 | * |
||
| 406 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
| 407 | * |
||
| 408 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
| 409 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
| 410 | * |
||
| 411 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 412 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
| 413 | * |
||
| 414 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
| 415 | */ |
||
| 416 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * Deletes a content object including all its versions and locations including their subtrees. |
||
| 423 | * |
||
| 424 | * @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) |
||
| 425 | * |
||
| 426 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 427 | */ |
||
| 428 | public function deleteContent(ContentInfo $contentInfo) |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Creates a draft from a published or archived version. |
||
| 435 | * |
||
| 436 | * If no version is given, the current published version is used. |
||
| 437 | * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
| 438 | * It can be changed on updating the version. |
||
| 439 | * |
||
| 440 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the draft |
||
| 441 | * |
||
| 442 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 443 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 444 | * @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 |
||
| 445 | * |
||
| 446 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 447 | */ |
||
| 448 | public function createContentDraft(ContentInfo $contentInfo, VersionInfo $versionInfo = null, User $user = null) |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Counts drafts for a user. |
||
| 455 | * |
||
| 456 | * If no user is given the number of drafts for the authenticated user are returned |
||
| 457 | * |
||
| 458 | * @param \eZ\Publish\API\Repository\Values\User\User $user The user to load drafts for, if defined, otherwise drafts for current-user |
||
| 459 | * |
||
| 460 | * @return int The number of drafts ({@link VersionInfo}) owned by the given user |
||
| 461 | */ |
||
| 462 | public function countContentDrafts(?User $user = null): int |
||
| 466 | |||
| 467 | /** |
||
| 468 | * Loads drafts for a user. |
||
| 469 | * |
||
| 470 | * If no user is given the drafts for the authenticated user are returned |
||
| 471 | * |
||
| 472 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
| 473 | * |
||
| 474 | * |
||
| 475 | * @throws \Exception |
||
| 476 | */ |
||
| 477 | public function loadContentDrafts(User $user = null) |
||
| 481 | |||
| 482 | /** |
||
| 483 | * {@inheritdoc} |
||
| 484 | */ |
||
| 485 | public function loadContentDraftList(?User $user = null, int $offset = 0, int $limit = -1): ContentDraftList |
||
| 489 | |||
| 490 | /** |
||
| 491 | * Updates the fields of a draft. |
||
| 492 | * |
||
| 493 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 494 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 495 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentUpdateStruct is not valid |
||
| 496 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value |
||
| 497 | * |
||
| 498 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 499 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 500 | * |
||
| 501 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
| 502 | */ |
||
| 503 | public function updateContent(VersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct) |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Publishes a content version. |
||
| 510 | * |
||
| 511 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 512 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 513 | * |
||
| 514 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 515 | * @param string[] $translations |
||
| 516 | * |
||
| 517 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 518 | * |
||
| 519 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 520 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 521 | */ |
||
| 522 | public function publishVersion(VersionInfo $versionInfo, array $translations = Language::ALL) |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Removes the given version. |
||
| 529 | * |
||
| 530 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
| 531 | * published state or is a last version of the Content |
||
| 532 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
| 533 | * |
||
| 534 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 535 | */ |
||
| 536 | public function deleteVersion(VersionInfo $versionInfo) |
||
| 540 | |||
| 541 | /** |
||
| 542 | * Loads all versions for the given content. |
||
| 543 | * |
||
| 544 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
| 545 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the given status is invalid |
||
| 546 | * |
||
| 547 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 548 | * @param int|null $status |
||
| 549 | * |
||
| 550 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
| 551 | */ |
||
| 552 | public function loadVersions(ContentInfo $contentInfo, ?int $status = null) |
||
| 556 | |||
| 557 | /** |
||
| 558 | * Copies the content to a new location. If no version is given, |
||
| 559 | * all versions are copied, otherwise only the given version. |
||
| 560 | * |
||
| 561 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
| 562 | * |
||
| 563 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 564 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
| 565 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 566 | * |
||
| 567 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 568 | */ |
||
| 569 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, VersionInfo $versionInfo = null) |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Finds content objects for the given query. |
||
| 576 | * |
||
| 577 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
| 578 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
| 579 | * Currently supported: <code>array("languages" => array(<language1>,..))</code>. |
||
| 580 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
| 581 | * |
||
| 582 | * @return \eZ\Publish\API\Repository\Values\Content\SearchResult |
||
| 583 | */ |
||
| 584 | public function findContent(Query $query, array $languageFilter, $filterOnUserPermissions = true) |
||
| 588 | |||
| 589 | /** |
||
| 590 | * Performs a query for a single content object. |
||
| 591 | * |
||
| 592 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the object was not found by the query or due to permissions |
||
| 593 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the query would return more than one result |
||
| 594 | * |
||
| 595 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
| 596 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
| 597 | * Currently supported: <code>array("languages" => array(<language1>,..))</code>. |
||
| 598 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
| 599 | * |
||
| 600 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 601 | */ |
||
| 602 | public function findSingle(Query $query, array $languageFilter, $filterOnUserPermissions = true) |
||
| 606 | |||
| 607 | /** |
||
| 608 | * Loads all outgoing relations for the given version. |
||
| 609 | * |
||
| 610 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 611 | * |
||
| 612 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 613 | * |
||
| 614 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 615 | */ |
||
| 616 | public function loadRelations(VersionInfo $versionInfo) |
||
| 620 | |||
| 621 | /** |
||
| 622 | * {@inheritdoc} |
||
| 623 | */ |
||
| 624 | public function countReverseRelations(ContentInfo $contentInfo): int |
||
| 628 | |||
| 629 | /** |
||
| 630 | * Loads all incoming relations for a content object. |
||
| 631 | * |
||
| 632 | * The relations come only |
||
| 633 | * from published versions of the source content objects |
||
| 634 | * |
||
| 635 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 636 | * |
||
| 637 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 638 | * |
||
| 639 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 640 | */ |
||
| 641 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
| 645 | |||
| 646 | /** |
||
| 647 | * {@inheritdoc} |
||
| 648 | */ |
||
| 649 | public function loadReverseRelationList(ContentInfo $contentInfo, int $offset = 0, int $limit = -1): RelationList |
||
| 653 | |||
| 654 | /** |
||
| 655 | * Adds a relation of type common. |
||
| 656 | * |
||
| 657 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
| 658 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 659 | * |
||
| 660 | * The source of the relation is the content and version |
||
| 661 | * referenced by $versionInfo. |
||
| 662 | * |
||
| 663 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 664 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
| 665 | * |
||
| 666 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
| 667 | */ |
||
| 668 | public function addRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 672 | |||
| 673 | /** |
||
| 674 | * Removes a relation of type COMMON from a draft. |
||
| 675 | * |
||
| 676 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
| 677 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 678 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
| 679 | * |
||
| 680 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 681 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
| 682 | */ |
||
| 683 | public function deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 687 | |||
| 688 | /** |
||
| 689 | * Instantiates a new content create struct object. |
||
| 690 | * |
||
| 691 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable |
||
| 692 | * |
||
| 693 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 694 | * @param string $mainLanguageCode |
||
| 695 | * |
||
| 696 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 697 | */ |
||
| 698 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 702 | |||
| 703 | /** |
||
| 704 | * Instantiates a new content meta data update struct. |
||
| 705 | * |
||
| 706 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
| 707 | */ |
||
| 708 | public function newContentMetadataUpdateStruct() |
||
| 712 | |||
| 713 | /** |
||
| 714 | * Instantiates a new content update struct. |
||
| 715 | * |
||
| 716 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
| 717 | */ |
||
| 718 | public function newContentUpdateStruct() |
||
| 722 | |||
| 723 | // Ignore this eZ Publish 5 feature by now. |
||
| 724 | |||
| 725 | // @codeCoverageIgnoreStart |
||
| 726 | |||
| 727 | /** |
||
| 728 | * {@inheritdoc} |
||
| 729 | */ |
||
| 730 | public function removeTranslation(ContentInfo $contentInfo, $languageCode) |
||
| 734 | |||
| 735 | /** |
||
| 736 | * {@inheritdoc} |
||
| 737 | */ |
||
| 738 | public function deleteTranslation(ContentInfo $contentInfo, $languageCode) |
||
| 742 | |||
| 743 | /** |
||
| 744 | * {@inheritdoc} |
||
| 745 | */ |
||
| 746 | public function deleteTranslationFromDraft(VersionInfo $versionInfo, $languageCode) |
||
| 750 | |||
| 751 | /** |
||
| 752 | * Bulk-load Content items by the list of ContentInfo Value Objects. |
||
| 753 | * |
||
| 754 | * Note: it does not throw exceptions on load, just ignores erroneous Content item. |
||
| 755 | * |
||
| 756 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList |
||
| 757 | * @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on |
||
| 758 | * returned value object. If not given all languages are returned. |
||
| 759 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true, |
||
| 760 | * unless all languages have been asked for. |
||
| 761 | * |
||
| 762 | * @throws \Exception Not implemented |
||
| 763 | */ |
||
| 764 | public function loadContentListByContentInfo(array $contentInfoList, array $languages = [], $useAlwaysAvailable = true) |
||
| 768 | |||
| 769 | /** |
||
| 770 | * Hides Content by making all the Locations appear hidden. |
||
| 771 | * It does not persist hidden state on Location object itself. |
||
| 772 | * |
||
| 773 | * Content hidden by this API can be revealed by revealContent API. |
||
| 774 | * |
||
| 775 | * @see revealContent |
||
| 776 | * |
||
| 777 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 778 | */ |
||
| 779 | public function hideContent(ContentInfo $contentInfo): void |
||
| 783 | |||
| 784 | /** |
||
| 785 | * Reveals Content hidden by hideContent API. |
||
| 786 | * Locations which were hidden before hiding Content will remain hidden. |
||
| 787 | * |
||
| 788 | * @see hideContent |
||
| 789 | * |
||
| 790 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 791 | */ |
||
| 792 | public function revealContent(ContentInfo $contentInfo): void |
||
| 796 | } |
||
| 797 |
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.