Complex classes like RoleService 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 RoleService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 45 | class RoleService implements RoleServiceInterface |
||
| 46 | { |
||
| 47 | /** @var \eZ\Publish\API\Repository\Repository */ |
||
| 48 | protected $repository; |
||
| 49 | |||
| 50 | /** @var \eZ\Publish\SPI\Persistence\User\Handler */ |
||
| 51 | protected $userHandler; |
||
| 52 | |||
| 53 | /** @var \eZ\Publish\Core\Repository\Permission\LimitationService */ |
||
| 54 | protected $limitationService; |
||
| 55 | |||
| 56 | /** @var \eZ\Publish\Core\Repository\Helper\RoleDomainMapper */ |
||
| 57 | protected $roleDomainMapper; |
||
| 58 | |||
| 59 | /** @var array */ |
||
| 60 | protected $settings; |
||
| 61 | |||
| 62 | /** @var \eZ\Publish\API\Repository\PermissionResolver */ |
||
| 63 | private $permissionResolver; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Setups service with reference to repository object that created it & corresponding handler. |
||
| 67 | * |
||
| 68 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 69 | * @param \eZ\Publish\SPI\Persistence\User\Handler $userHandler |
||
| 70 | * @param \eZ\Publish\Core\Repository\Permission\LimitationService $limitationService |
||
| 71 | * @param \eZ\Publish\Core\Repository\Helper\RoleDomainMapper $roleDomainMapper |
||
| 72 | * @param array $settings |
||
| 73 | */ |
||
| 74 | public function __construct( |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Creates a new RoleDraft. |
||
| 91 | * |
||
| 92 | * @since 6.0 |
||
| 93 | * |
||
| 94 | * @param \eZ\Publish\API\Repository\Values\User\RoleCreateStruct $roleCreateStruct |
||
| 95 | * |
||
| 96 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 97 | * |
||
| 98 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 99 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the name of the role already exists or if limitation of the same type |
||
| 100 | * is repeated in the policy create struct or if limitation is not allowed on module/function |
||
| 101 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a RoleDraft |
||
| 102 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a policy limitation in the $roleCreateStruct is not valid |
||
| 103 | */ |
||
| 104 | public function createRole(APIRoleCreateStruct $roleCreateStruct): APIRoleDraft |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Creates a new RoleDraft for an existing Role. |
||
| 147 | * |
||
| 148 | * @since 6.0 |
||
| 149 | * |
||
| 150 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 151 | * |
||
| 152 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 153 | * |
||
| 154 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 155 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the Role already has a RoleDraft that will need to be removed first |
||
| 156 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a RoleDraft |
||
| 157 | */ |
||
| 158 | public function createRoleDraft(APIRole $role): APIRoleDraft |
||
| 185 | |||
| 186 | public function copyRole(APIRole $role, APIRoleCopyStruct $roleCopyStruct): APIRole |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Loads a RoleDraft for the given id. |
||
| 240 | * |
||
| 241 | * @since 6.0 |
||
| 242 | * |
||
| 243 | * @param int $id |
||
| 244 | * |
||
| 245 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 246 | * |
||
| 247 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 248 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 249 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a RoleDraft with the given id was not found |
||
| 250 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a RoleDraft |
||
| 251 | */ |
||
| 252 | public function loadRoleDraft(int $id): APIRoleDraft |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Loads a RoleDraft by the ID of the role it was created from. |
||
| 267 | * |
||
| 268 | * @param int $roleId ID of the role the draft was created from. |
||
| 269 | * |
||
| 270 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 271 | * |
||
| 272 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 273 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 274 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a RoleDraft with the given id was not found |
||
| 275 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
| 276 | */ |
||
| 277 | public function loadRoleDraftByRoleId(int $roleId): APIRoleDraft |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Updates the properties of a RoleDraft. |
||
| 292 | * |
||
| 293 | * @since 6.0 |
||
| 294 | * |
||
| 295 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 296 | * @param \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct $roleUpdateStruct |
||
| 297 | * |
||
| 298 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 299 | * |
||
| 300 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 301 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the identifier of the RoleDraft already exists |
||
| 302 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 303 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a RoleDraft |
||
| 304 | */ |
||
| 305 | public function updateRoleDraft(APIRoleDraft $roleDraft, RoleUpdateStruct $roleUpdateStruct): APIRoleDraft |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Adds a new policy to the RoleDraft. |
||
| 358 | * |
||
| 359 | * @since 6.0 |
||
| 360 | * |
||
| 361 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 362 | * @param \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct $policyCreateStruct |
||
| 363 | * |
||
| 364 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 365 | * |
||
| 366 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 367 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy create |
||
| 368 | * struct or if limitation is not allowed on module/function |
||
| 369 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 370 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyCreateStruct is not valid |
||
| 371 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to add a policy |
||
| 372 | */ |
||
| 373 | public function addPolicyByRoleDraft(APIRoleDraft $roleDraft, APIPolicyCreateStruct $policyCreateStruct): APIRoleDraft |
||
| 420 | |||
| 421 | /** |
||
| 422 | * Removes a policy from a RoleDraft. |
||
| 423 | * |
||
| 424 | * @since 6.0 |
||
| 425 | * |
||
| 426 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 427 | * @param \eZ\Publish\API\Repository\Values\User\PolicyDraft $policyDraft the policy to remove from the RoleDraft |
||
| 428 | * |
||
| 429 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
| 430 | * |
||
| 431 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 432 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if policy does not belong to the given RoleDraft |
||
| 433 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 434 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a policy |
||
| 435 | */ |
||
| 436 | public function removePolicyByRoleDraft(APIRoleDraft $roleDraft, PolicyDraft $policyDraft): APIRoleDraft |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Updates the limitations of a policy. The module and function cannot be changed and |
||
| 453 | * the limitations are replaced by the ones in $roleUpdateStruct. |
||
| 454 | * |
||
| 455 | * @since 6.0 |
||
| 456 | * |
||
| 457 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 458 | * @param \eZ\Publish\API\Repository\Values\User\PolicyDraft $policy |
||
| 459 | * @param \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct $policyUpdateStruct |
||
| 460 | * |
||
| 461 | * @return \eZ\Publish\API\Repository\Values\User\PolicyDraft |
||
| 462 | * |
||
| 463 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 464 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy update |
||
| 465 | * struct or if limitation is not allowed on module/function |
||
| 466 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyUpdateStruct is not valid |
||
| 467 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a policy |
||
| 468 | */ |
||
| 469 | public function updatePolicyByRoleDraft( |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Deletes the given RoleDraft. |
||
| 523 | * |
||
| 524 | * @since 6.0 |
||
| 525 | * |
||
| 526 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 527 | * |
||
| 528 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 529 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 530 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 531 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete this RoleDraft |
||
| 532 | */ |
||
| 533 | public function deleteRoleDraft(APIRoleDraft $roleDraft): void |
||
| 546 | |||
| 547 | /** |
||
| 548 | * Publishes a given RoleDraft. |
||
| 549 | * |
||
| 550 | * @since 6.0 |
||
| 551 | * |
||
| 552 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
| 553 | * |
||
| 554 | * |
||
| 555 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the role draft cannot be loaded |
||
| 556 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 557 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to publish this RoleDraft |
||
| 558 | */ |
||
| 559 | public function publishRoleDraft(APIRoleDraft $roleDraft): void |
||
| 584 | |||
| 585 | /** |
||
| 586 | * Loads a role for the given id. |
||
| 587 | * |
||
| 588 | * @param int $id |
||
| 589 | * |
||
| 590 | * @return \eZ\Publish\Core\Repository\Values\User\Role |
||
| 591 | * |
||
| 592 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 593 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 594 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given id was not found |
||
| 595 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
| 596 | */ |
||
| 597 | public function loadRole(int $id): APIRole |
||
| 609 | |||
| 610 | /** |
||
| 611 | * Loads a role for the given identifier. |
||
| 612 | * |
||
| 613 | * @param string $identifier |
||
| 614 | * |
||
| 615 | * @return \eZ\Publish\API\Repository\Values\User\Role |
||
| 616 | * |
||
| 617 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 618 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 619 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given name was not found |
||
| 620 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
| 621 | */ |
||
| 622 | public function loadRoleByIdentifier(string $identifier): APIRole |
||
| 634 | |||
| 635 | /** |
||
| 636 | * Loads all roles, excluding the ones the current user is not allowed to read. |
||
| 637 | * |
||
| 638 | * @return \eZ\Publish\API\Repository\Values\User\Role[] |
||
| 639 | */ |
||
| 640 | public function loadRoles(): iterable |
||
| 658 | |||
| 659 | /** |
||
| 660 | * Deletes the given role. |
||
| 661 | * |
||
| 662 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 663 | * |
||
| 664 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 665 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 666 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 667 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete this role |
||
| 668 | */ |
||
| 669 | public function deleteRole(APIRole $role): void |
||
| 686 | |||
| 687 | /** |
||
| 688 | * Assigns a role to the given user group. |
||
| 689 | * |
||
| 690 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 691 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
| 692 | * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation) |
||
| 693 | * |
||
| 694 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 695 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If assignment already exists |
||
| 696 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 697 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign a role |
||
| 698 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if $roleLimitation is not valid |
||
| 699 | */ |
||
| 700 | public function assignRoleToUserGroup(APIRole $role, UserGroup $userGroup, RoleLimitation $roleLimitation = null): void |
||
| 736 | |||
| 737 | /** |
||
| 738 | * Assigns a role to the given user. |
||
| 739 | * |
||
| 740 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 741 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
| 742 | * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation) |
||
| 743 | * |
||
| 744 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 745 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If assignment already exists |
||
| 746 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 747 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if $roleLimitation is not valid |
||
| 748 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign a role |
||
| 749 | */ |
||
| 750 | public function assignRoleToUser(APIRole $role, User $user, RoleLimitation $roleLimitation = null): void |
||
| 786 | |||
| 787 | /** |
||
| 788 | * Removes the given role assignment. |
||
| 789 | * |
||
| 790 | * @param \eZ\Publish\API\Repository\Values\User\RoleAssignment $roleAssignment |
||
| 791 | * |
||
| 792 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 793 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 794 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 795 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role assignment |
||
| 796 | */ |
||
| 797 | public function removeRoleAssignment(RoleAssignment $roleAssignment): void |
||
| 814 | |||
| 815 | /** |
||
| 816 | * Loads a role assignment for the given id. |
||
| 817 | * |
||
| 818 | * @param int $roleAssignmentId |
||
| 819 | * |
||
| 820 | * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment |
||
| 821 | * |
||
| 822 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 823 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 824 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the role assignment was not found |
||
| 825 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
| 826 | */ |
||
| 827 | public function loadRoleAssignment(int $roleAssignmentId): RoleAssignment |
||
| 863 | |||
| 864 | /** |
||
| 865 | * Returns the assigned user and user groups to this role. |
||
| 866 | * |
||
| 867 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 868 | * |
||
| 869 | * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment[] |
||
| 870 | * |
||
| 871 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 872 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 873 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read a role |
||
| 874 | */ |
||
| 875 | public function getRoleAssignments(APIRole $role): iterable |
||
| 911 | |||
| 912 | /** |
||
| 913 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUser() |
||
| 914 | * |
||
| 915 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
| 916 | * @param bool $inherited |
||
| 917 | * |
||
| 918 | * @return iterable |
||
| 919 | * |
||
| 920 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 921 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 922 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 923 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 924 | */ |
||
| 925 | public function getRoleAssignmentsForUser(User $user, bool $inherited = false): iterable |
||
| 954 | |||
| 955 | /** |
||
| 956 | * Returns the roles assigned to the given user group, excluding the ones the current user is not allowed to read. |
||
| 957 | * |
||
| 958 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
| 959 | * |
||
| 960 | * @return \eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment[] |
||
| 961 | * |
||
| 962 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 963 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 964 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 965 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 966 | */ |
||
| 967 | public function getRoleAssignmentsForUserGroup(UserGroup $userGroup): iterable |
||
| 985 | |||
| 986 | /** |
||
| 987 | * Instantiates a role create class. |
||
| 988 | * |
||
| 989 | * @param string $name |
||
| 990 | * |
||
| 991 | * @return \eZ\Publish\API\Repository\Values\User\RoleCreateStruct |
||
| 992 | */ |
||
| 993 | public function newRoleCreateStruct(string $name): APIRoleCreateStruct |
||
| 1002 | |||
| 1003 | /** |
||
| 1004 | * Instantiates a role copy class. |
||
| 1005 | */ |
||
| 1006 | public function newRoleCopyStruct(string $name): APIRoleCopyStruct |
||
| 1015 | |||
| 1016 | /** |
||
| 1017 | * Instantiates a policy create class. |
||
| 1018 | * |
||
| 1019 | * @param string $module |
||
| 1020 | * @param string $function |
||
| 1021 | * |
||
| 1022 | * @return \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct |
||
| 1023 | */ |
||
| 1024 | public function newPolicyCreateStruct(string $module, string $function): APIPolicyCreateStruct |
||
| 1034 | |||
| 1035 | /** |
||
| 1036 | * Instantiates a policy update class. |
||
| 1037 | * |
||
| 1038 | * @return \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct |
||
| 1039 | */ |
||
| 1040 | public function newPolicyUpdateStruct(): APIPolicyUpdateStruct |
||
| 1048 | |||
| 1049 | /** |
||
| 1050 | * Instantiates a policy update class. |
||
| 1051 | * |
||
| 1052 | * @return \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct |
||
| 1053 | */ |
||
| 1054 | public function newRoleUpdateStruct(): RoleUpdateStruct |
||
| 1058 | |||
| 1059 | /** |
||
| 1060 | * Returns the LimitationType registered with the given identifier. |
||
| 1061 | * |
||
| 1062 | * Returns the correct implementation of API Limitation value object |
||
| 1063 | * based on provided identifier |
||
| 1064 | * |
||
| 1065 | * @param string $identifier |
||
| 1066 | * |
||
| 1067 | * @return \eZ\Publish\SPI\Limitation\Type |
||
| 1068 | * |
||
| 1069 | * @throws \RuntimeException if there is no LimitationType with $identifier |
||
| 1070 | */ |
||
| 1071 | public function getLimitationType(string $identifier): Type |
||
| 1075 | |||
| 1076 | /** |
||
| 1077 | * Returns the LimitationType's assigned to a given module/function. |
||
| 1078 | * |
||
| 1079 | * Typically used for: |
||
| 1080 | * - Internal validation limitation value use on Policies |
||
| 1081 | * - Role admin gui for editing policy limitations incl list limitation options via valueSchema() |
||
| 1082 | * |
||
| 1083 | * @param string $module Legacy name of "controller", it's a unique identifier like "content" |
||
| 1084 | * @param string $function Legacy name of a controller "action", it's a unique within the controller like "read" |
||
| 1085 | * |
||
| 1086 | * @return \eZ\Publish\SPI\Limitation\Type[] |
||
| 1087 | * |
||
| 1088 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If module/function to limitation type mapping |
||
| 1089 | * refers to a non existing identifier. |
||
| 1090 | */ |
||
| 1091 | public function getLimitationTypesByModuleFunction(string $module, string $function): iterable |
||
| 1112 | |||
| 1113 | /** |
||
| 1114 | * Validates Policies and Limitations in Role create struct. |
||
| 1115 | * |
||
| 1116 | * @uses ::validatePolicy() |
||
| 1117 | * |
||
| 1118 | * @param \eZ\Publish\API\Repository\Values\User\RoleCreateStruct $roleCreateStruct |
||
| 1119 | * |
||
| 1120 | * @return \eZ\Publish\Core\FieldType\ValidationError[][][] |
||
| 1121 | * |
||
| 1122 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 1123 | */ |
||
| 1124 | protected function validateRoleCreateStruct(APIRoleCreateStruct $roleCreateStruct): iterable |
||
| 1141 | |||
| 1142 | /** |
||
| 1143 | * Validates Policies and Limitations in Role copy struct. |
||
| 1144 | * |
||
| 1145 | * @uses ::validatePolicy() |
||
| 1146 | * |
||
| 1147 | * @return \eZ\Publish\Core\FieldType\ValidationError[][][] |
||
| 1148 | */ |
||
| 1149 | protected function validateRoleCopyStruct(APIRoleCopyStruct $roleCopyStruct): array |
||
| 1166 | |||
| 1167 | /** |
||
| 1168 | * Validates Policy context: Limitations on a module and function. |
||
| 1169 | * |
||
| 1170 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the same limitation is repeated or if |
||
| 1171 | * limitation is not allowed on module/function |
||
| 1172 | * |
||
| 1173 | * @param string $module |
||
| 1174 | * @param string $function |
||
| 1175 | * @param \eZ\Publish\API\Repository\Values\User\Limitation[] $limitations |
||
| 1176 | * |
||
| 1177 | * @return \eZ\Publish\Core\FieldType\ValidationError[][] |
||
| 1178 | */ |
||
| 1179 | protected function validatePolicy(string $module, string $function, array $limitations): iterable |
||
| 1204 | |||
| 1205 | /** |
||
| 1206 | * Validate that assignments not already exists and filter validations against existing. |
||
| 1207 | * |
||
| 1208 | * @param int $contentId |
||
| 1209 | * @param \eZ\Publish\SPI\Persistence\User\Role $spiRole |
||
| 1210 | * @param array|null $limitation |
||
| 1211 | * |
||
| 1212 | * @return array[]|null Filtered version of $limitation |
||
| 1213 | * |
||
| 1214 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If assignment already exists |
||
| 1215 | */ |
||
| 1216 | protected function checkAssignmentAndFilterLimitationValues( |
||
| 1261 | |||
| 1262 | /** |
||
| 1263 | * Deletes a policy. |
||
| 1264 | * |
||
| 1265 | * Used by {@link removePolicy()} and {@link deletePolicy()} |
||
| 1266 | * |
||
| 1267 | * @param \eZ\Publish\API\Repository\Values\User\Policy $policy |
||
| 1268 | * |
||
| 1269 | * @throws \Exception |
||
| 1270 | */ |
||
| 1271 | protected function internalDeletePolicy(APIPolicy $policy): void |
||
| 1282 | } |
||
| 1283 |