Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
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 |
||
| 42 | class ContentService implements ContentServiceInterface |
||
| 43 | { |
||
| 44 | /** |
||
| 45 | * Aggregated service. |
||
| 46 | * |
||
| 47 | * @var \eZ\Publish\API\Repository\ContentService |
||
| 48 | */ |
||
| 49 | protected $service; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * SignalDispatcher. |
||
| 53 | * |
||
| 54 | * @var \eZ\Publish\Core\SignalSlot\SignalDispatcher |
||
| 55 | */ |
||
| 56 | protected $signalDispatcher; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Constructor. |
||
| 60 | * |
||
| 61 | * Construct service object from aggregated service and signal |
||
| 62 | * dispatcher |
||
| 63 | * |
||
| 64 | * @param \eZ\Publish\API\Repository\ContentService $service |
||
| 65 | * @param \eZ\Publish\Core\SignalSlot\SignalDispatcher $signalDispatcher |
||
| 66 | */ |
||
| 67 | public function __construct(ContentServiceInterface $service, SignalDispatcher $signalDispatcher) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Loads a content info object. |
||
| 75 | * |
||
| 76 | * To load fields use loadContent |
||
| 77 | * |
||
| 78 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 79 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 80 | * |
||
| 81 | * @param int $contentId |
||
| 82 | * |
||
| 83 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 84 | */ |
||
| 85 | public function loadContentInfo($contentId) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * {@inheritdoc} |
||
| 92 | */ |
||
| 93 | public function loadContentInfoList(array $contentIds): iterable |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Loads a content info object for the given remoteId. |
||
| 100 | * |
||
| 101 | * To load fields use loadContent |
||
| 102 | * |
||
| 103 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 104 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist |
||
| 105 | * |
||
| 106 | * @param string $remoteId |
||
| 107 | * |
||
| 108 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 109 | */ |
||
| 110 | public function loadContentInfoByRemoteId($remoteId) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Loads a version info of the given content object. |
||
| 117 | * |
||
| 118 | * If no version number is given, the method returns the current version |
||
| 119 | * |
||
| 120 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 121 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 122 | * |
||
| 123 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 124 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 125 | * |
||
| 126 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 127 | */ |
||
| 128 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Loads a version info of the given content object id. |
||
| 135 | * |
||
| 136 | * If no version number is given, the method returns the current version |
||
| 137 | * |
||
| 138 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 139 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 140 | * |
||
| 141 | * @param mixed $contentId |
||
| 142 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 143 | * |
||
| 144 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 145 | */ |
||
| 146 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Loads content in a version for the given content info object. |
||
| 153 | * |
||
| 154 | * If no version number is given, the method returns the current version |
||
| 155 | * |
||
| 156 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist |
||
| 157 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 158 | * |
||
| 159 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 160 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 161 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 162 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 163 | * |
||
| 164 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 165 | */ |
||
| 166 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Loads content in the version given by version info. |
||
| 173 | * |
||
| 174 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 175 | * |
||
| 176 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 177 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 178 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 179 | * |
||
| 180 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 181 | */ |
||
| 182 | public function loadContentByVersionInfo(VersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Loads content in a version of the given content object. |
||
| 189 | * |
||
| 190 | * If no version number is given, the method returns the current version |
||
| 191 | * |
||
| 192 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
| 193 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 194 | * |
||
| 195 | * @param int $contentId |
||
| 196 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 197 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 198 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 199 | * |
||
| 200 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 201 | */ |
||
| 202 | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Loads content in a version for the content object reference by the given remote id. |
||
| 209 | * |
||
| 210 | * If no version is given, the method returns the current version |
||
| 211 | * |
||
| 212 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
| 213 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 214 | * |
||
| 215 | * @param string $remoteId |
||
| 216 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 217 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 218 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 219 | * |
||
| 220 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 221 | */ |
||
| 222 | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Creates a new content draft assigned to the authenticated user. |
||
| 229 | * |
||
| 230 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
| 231 | * but this required special rights for the authenticated user |
||
| 232 | * (this is useful for content staging where the transfer process does not |
||
| 233 | * have to authenticate with the user which created the content object in the source server). |
||
| 234 | * The user has to publish the draft if it should be visible. |
||
| 235 | * In 4.x at least one location has to be provided in the location creation array. |
||
| 236 | * |
||
| 237 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
| 238 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is a provided remoteId which exists in the system |
||
| 239 | * or there is no location provided (4.x) or multiple locations |
||
| 240 | * are under the same parent or if the a field value is not accepted by the field type |
||
| 241 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid |
||
| 242 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing or is set to an empty value |
||
| 243 | * |
||
| 244 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 245 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
| 246 | * |
||
| 247 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 248 | */ |
||
| 249 | public function createContent(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array()) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Updates the metadata. |
||
| 266 | * |
||
| 267 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
| 268 | * |
||
| 269 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
| 270 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
| 271 | * |
||
| 272 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 273 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
| 274 | * |
||
| 275 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
| 276 | */ |
||
| 277 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Deletes a content object including all its versions and locations including their subtrees. |
||
| 293 | * |
||
| 294 | * @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) |
||
| 295 | * |
||
| 296 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 297 | * |
||
| 298 | * @return mixed[] Affected Location Id's |
||
| 299 | */ |
||
| 300 | public function deleteContent(ContentInfo $contentInfo) |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Creates a draft from a published or archived version. |
||
| 317 | * |
||
| 318 | * If no version is given, the current published version is used. |
||
| 319 | * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
| 320 | * It can be changed on updating the version. |
||
| 321 | * |
||
| 322 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the draft |
||
| 323 | * |
||
| 324 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 325 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 326 | * @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 |
||
| 327 | * |
||
| 328 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 329 | */ |
||
| 330 | public function createContentDraft(ContentInfo $contentInfo, VersionInfo $versionInfo = null, User $user = null) |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Loads drafts for a user. |
||
| 349 | * |
||
| 350 | * If no user is given the drafts for the authenticated user a returned |
||
| 351 | * |
||
| 352 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load the draft list |
||
| 353 | * |
||
| 354 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
| 355 | * |
||
| 356 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] the drafts ({@link VersionInfo}) owned by the given user |
||
| 357 | */ |
||
| 358 | public function loadContentDrafts(User $user = null) |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Translate a version. |
||
| 365 | * |
||
| 366 | * updates the destination version given in $translationInfo with the provided translated fields in $translationValues |
||
| 367 | * |
||
| 368 | * @example Examples/translation_5x.php |
||
| 369 | * |
||
| 370 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 371 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the given destination version is not a draft |
||
| 372 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value |
||
| 373 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $translationValues is not valid |
||
| 374 | * |
||
| 375 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 376 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationValues $translationValues |
||
| 377 | * @param \eZ\Publish\API\Repository\Values\User\User $user If set, this user is taken as modifier of the version |
||
| 378 | * |
||
| 379 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the translated fields |
||
| 380 | * |
||
| 381 | * @since 5.0 |
||
| 382 | */ |
||
| 383 | public function translateVersion(TranslationInfo $translationInfo, TranslationValues $translationValues, User $user = null) |
||
| 398 | |||
| 399 | /** |
||
| 400 | * Updates the fields of a draft. |
||
| 401 | * |
||
| 402 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 403 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 404 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentUpdateStruct is not valid |
||
| 405 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value |
||
| 406 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a field value is not accepted by the field type |
||
| 407 | * |
||
| 408 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 409 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 410 | * |
||
| 411 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
| 412 | */ |
||
| 413 | View Code Duplication | public function updateContent(VersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct) |
|
| 427 | |||
| 428 | /** |
||
| 429 | * Publishes a content version. |
||
| 430 | * |
||
| 431 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 432 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 433 | * |
||
| 434 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 435 | * |
||
| 436 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 437 | */ |
||
| 438 | View Code Duplication | public function publishVersion(VersionInfo $versionInfo) |
|
| 452 | |||
| 453 | /** |
||
| 454 | * Removes the given version. |
||
| 455 | * |
||
| 456 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
| 457 | * published state or is the last version of the Content |
||
| 458 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
| 459 | * |
||
| 460 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 461 | */ |
||
| 462 | View Code Duplication | public function deleteVersion(VersionInfo $versionInfo) |
|
| 476 | |||
| 477 | /** |
||
| 478 | * Loads all versions for the given content. |
||
| 479 | * |
||
| 480 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
| 481 | * |
||
| 482 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 483 | * |
||
| 484 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
| 485 | */ |
||
| 486 | public function loadVersions(ContentInfo $contentInfo) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Copies the content to a new location. If no version is given, |
||
| 493 | * all versions are copied, otherwise only the given version. |
||
| 494 | * |
||
| 495 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
| 496 | * |
||
| 497 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 498 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
| 499 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 500 | * |
||
| 501 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 502 | */ |
||
| 503 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, VersionInfo $versionInfo = null) |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Loads all outgoing relations for the given version. |
||
| 523 | * |
||
| 524 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 525 | * |
||
| 526 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 527 | * |
||
| 528 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 529 | */ |
||
| 530 | public function loadRelations(VersionInfo $versionInfo) |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Loads all incoming relations for a content object. |
||
| 537 | * |
||
| 538 | * The relations come only from published versions of the source content objects |
||
| 539 | * |
||
| 540 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 541 | * |
||
| 542 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 543 | * |
||
| 544 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 545 | */ |
||
| 546 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Adds a relation of type common. |
||
| 553 | * |
||
| 554 | * The source of the relation is the content and version |
||
| 555 | * referenced by $versionInfo. |
||
| 556 | * |
||
| 557 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
| 558 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 559 | * |
||
| 560 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 561 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
| 562 | * |
||
| 563 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
| 564 | */ |
||
| 565 | View Code Duplication | public function addRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) |
|
| 580 | |||
| 581 | /** |
||
| 582 | * Removes a relation of type COMMON from a draft. |
||
| 583 | * |
||
| 584 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
| 585 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 586 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
| 587 | * |
||
| 588 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 589 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
| 590 | */ |
||
| 591 | View Code Duplication | public function deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) |
|
| 606 | |||
| 607 | /** |
||
| 608 | * Adds translation information to the content object. |
||
| 609 | * |
||
| 610 | * @example Examples/translation_5x.php |
||
| 611 | * |
||
| 612 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed add a translation info |
||
| 613 | * |
||
| 614 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 615 | * |
||
| 616 | * @since 5.0 |
||
| 617 | */ |
||
| 618 | public function addTranslationInfo(TranslationInfo $translationInfo) |
||
| 627 | |||
| 628 | /** |
||
| 629 | * lists the translations done on this content object. |
||
| 630 | * |
||
| 631 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed read translation infos |
||
| 632 | * |
||
| 633 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 634 | * @param array $filter |
||
| 635 | * |
||
| 636 | * @todo TBD - filter by source version, destination version and languages |
||
| 637 | * |
||
| 638 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo[] |
||
| 639 | * |
||
| 640 | * @since 5.0 |
||
| 641 | */ |
||
| 642 | public function loadTranslationInfos(ContentInfo $contentInfo, array $filter = array()) |
||
| 646 | |||
| 647 | /** |
||
| 648 | * {@inheritdoc} |
||
| 649 | */ |
||
| 650 | public function removeTranslation(ContentInfo $contentInfo, $languageCode) |
||
| 658 | |||
| 659 | /** |
||
| 660 | * Delete Content item Translation from all Versions (including archived ones) of a Content Object. |
||
| 661 | * |
||
| 662 | * NOTE: this operation is risky and permanent, so user interface should provide a warning before performing it. |
||
| 663 | * |
||
| 664 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation |
||
| 665 | * is the Main Translation of a Content Item. |
||
| 666 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed |
||
| 667 | * to delete the content (in one of the locations of the given Content Item). |
||
| 668 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument |
||
| 669 | * is invalid for the given content. |
||
| 670 | * |
||
| 671 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 672 | * @param string $languageCode |
||
| 673 | * |
||
| 674 | * @since 6.13 |
||
| 675 | */ |
||
| 676 | public function deleteTranslation(ContentInfo $contentInfo, $languageCode) |
||
| 686 | |||
| 687 | /** |
||
| 688 | * Delete specified Translation from a Content Draft. |
||
| 689 | * |
||
| 690 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation |
||
| 691 | * is the only one the Content Draft has or it is the main Translation of a Content Object. |
||
| 692 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed |
||
| 693 | * to edit the Content (in one of the locations of the given Content Object). |
||
| 694 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument |
||
| 695 | * is invalid for the given Draft. |
||
| 696 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if specified Version was not found |
||
| 697 | * |
||
| 698 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo Content Version Draft |
||
| 699 | * @param string $languageCode Language code of the Translation to be removed |
||
| 700 | * |
||
| 701 | * @return \eZ\Publish\API\Repository\Values\Content\Content Content Draft w/o the specified Translation |
||
| 702 | * |
||
| 703 | * @since 6.12 |
||
| 704 | */ |
||
| 705 | public function deleteTranslationFromDraft(VersionInfo $versionInfo, $languageCode) |
||
| 709 | |||
| 710 | /** |
||
| 711 | * Bulk-load Content items by the list of ContentInfo Value Objects. |
||
| 712 | * |
||
| 713 | * Note: it does not throw exceptions on load, just ignores erroneous Content item. |
||
| 714 | * Moreover, since the method works on pre-loaded ContentInfo list, it is assumed that user is |
||
| 715 | * allowed to access every Content on the list. |
||
| 716 | * |
||
| 717 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList |
||
| 718 | * @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on |
||
| 719 | * returned value object. If not given all languages are returned. |
||
| 720 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true, |
||
| 721 | * unless all languages have been asked for. |
||
| 722 | * |
||
| 723 | * @return \eZ\Publish\API\Repository\Values\Content\Content[] list of Content items with Content Ids as keys |
||
| 724 | */ |
||
| 725 | public function loadContentListByContentInfo( |
||
| 736 | |||
| 737 | /** |
||
| 738 | * Hides Content by making all the Locations appear hidden. |
||
| 739 | * It does not persist hidden state on Location object itself. |
||
| 740 | * |
||
| 741 | * Content hidden by this API can be revealed by revealContent API. |
||
| 742 | * |
||
| 743 | * @see revealContent |
||
| 744 | * |
||
| 745 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 746 | */ |
||
| 747 | public function hideContent(ContentInfo $contentInfo): void |
||
| 756 | |||
| 757 | /** |
||
| 758 | * Reveals Content hidden by hideContent API. |
||
| 759 | * Locations which were hidden before hiding Content will remain hidden. |
||
| 760 | * |
||
| 761 | * @see hideContent |
||
| 762 | * |
||
| 763 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 764 | */ |
||
| 765 | public function revealContent(ContentInfo $contentInfo): void |
||
| 774 | |||
| 775 | /** |
||
| 776 | * Instantiates a new content create struct object. |
||
| 777 | * |
||
| 778 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable |
||
| 779 | * |
||
| 780 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 781 | * @param string $mainLanguageCode |
||
| 782 | * |
||
| 783 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 784 | */ |
||
| 785 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 789 | |||
| 790 | /** |
||
| 791 | * Instantiates a new content meta data update struct. |
||
| 792 | * |
||
| 793 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
| 794 | */ |
||
| 795 | public function newContentMetadataUpdateStruct() |
||
| 799 | |||
| 800 | /** |
||
| 801 | * Instantiates a new content update struct. |
||
| 802 | * |
||
| 803 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
| 804 | */ |
||
| 805 | public function newContentUpdateStruct() |
||
| 809 | } |
||
| 810 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: