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 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 |
||
50 | class RoleService implements RoleServiceInterface |
||
51 | { |
||
52 | /** |
||
53 | * @var \eZ\Publish\API\Repository\Repository |
||
54 | */ |
||
55 | protected $repository; |
||
56 | |||
57 | /** |
||
58 | * @var \eZ\Publish\SPI\Persistence\User\Handler |
||
59 | */ |
||
60 | protected $userHandler; |
||
61 | |||
62 | /** |
||
63 | * @var \eZ\Publish\Core\Repository\Helper\LimitationService |
||
64 | */ |
||
65 | protected $limitationService; |
||
66 | |||
67 | /** |
||
68 | * @var \eZ\Publish\Core\Repository\Helper\RoleDomainMapper |
||
69 | */ |
||
70 | protected $roleDomainMapper; |
||
71 | |||
72 | /** |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $settings; |
||
76 | |||
77 | /** |
||
78 | * Setups service with reference to repository object that created it & corresponding handler. |
||
79 | * |
||
80 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
81 | * @param \eZ\Publish\SPI\Persistence\User\Handler $userHandler |
||
82 | * @param \eZ\Publish\Core\Repository\Helper\LimitationService $limitationService |
||
83 | * @param \eZ\Publish\Core\Repository\Helper\RoleDomainMapper $roleDomainMapper |
||
84 | * @param array $settings |
||
85 | */ |
||
86 | public function __construct( |
||
126 | |||
127 | /** |
||
128 | * Creates a new RoleDraft. |
||
129 | * |
||
130 | * @since 6.0 |
||
131 | * |
||
132 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a RoleDraft |
||
133 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
134 | * if the name of the role already exists or if limitation of the same type |
||
135 | * is repeated in the policy create struct or if limitation is not allowed on module/function |
||
136 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a policy limitation in the $roleCreateStruct is not valid |
||
137 | * |
||
138 | * @param \eZ\Publish\API\Repository\Values\User\RoleCreateStruct $roleCreateStruct |
||
139 | * |
||
140 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
141 | */ |
||
142 | public function createRole(APIRoleCreateStruct $roleCreateStruct) |
||
182 | |||
183 | /** |
||
184 | * Creates a new RoleDraft for an existing Role. |
||
185 | * |
||
186 | * @since 6.0 |
||
187 | * |
||
188 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a RoleDraft |
||
189 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the Role already has a RoleDraft that will need to be removed first |
||
190 | * |
||
191 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
192 | * |
||
193 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
194 | */ |
||
195 | View Code Duplication | public function createRoleDraft(APIRole $role) |
|
222 | |||
223 | /** |
||
224 | * Loads a RoleDraft for the given id. |
||
225 | * |
||
226 | * @since 6.0 |
||
227 | * |
||
228 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this RoleDraft |
||
229 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a RoleDraft with the given id was not found |
||
230 | * |
||
231 | * @param mixed $id |
||
232 | * |
||
233 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
234 | */ |
||
235 | View Code Duplication | public function loadRoleDraft($id) |
|
245 | |||
246 | /** |
||
247 | * Loads a RoleDraft by the ID of the role it was created from. |
||
248 | * |
||
249 | * @param mixed $roleId ID of the role the draft was created from. |
||
250 | * |
||
251 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
252 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a RoleDraft with the given id was not found |
||
253 | * |
||
254 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
255 | */ |
||
256 | View Code Duplication | public function loadRoleDraftByRoleId($roleId) |
|
266 | |||
267 | /** |
||
268 | * Updates the properties of a RoleDraft. |
||
269 | * |
||
270 | * @since 6.0 |
||
271 | * |
||
272 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a RoleDraft |
||
273 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the identifier of the RoleDraft already exists |
||
274 | * |
||
275 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
276 | * @param \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct $roleUpdateStruct |
||
277 | * |
||
278 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
279 | */ |
||
280 | public function updateRoleDraft(APIRoleDraft $roleDraft, RoleUpdateStruct $roleUpdateStruct) |
||
330 | |||
331 | /** |
||
332 | * Adds a new policy to the RoleDraft. |
||
333 | * |
||
334 | * @since 6.0 |
||
335 | * |
||
336 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to add a policy |
||
337 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy create |
||
338 | * struct or if limitation is not allowed on module/function |
||
339 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyCreateStruct is not valid |
||
340 | * |
||
341 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
342 | * @param \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct $policyCreateStruct |
||
343 | * |
||
344 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
||
345 | */ |
||
346 | View Code Duplication | public function addPolicyByRoleDraft(APIRoleDraft $roleDraft, APIPolicyCreateStruct $policyCreateStruct) |
|
393 | |||
394 | /** |
||
395 | * Removes a policy from a RoleDraft. |
||
396 | * |
||
397 | * @since 6.0 |
||
398 | * |
||
399 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a policy |
||
400 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if policy does not belong to the given RoleDraft |
||
401 | * |
||
402 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
403 | * @param PolicyDraft $policyDraft the policy to remove from the RoleDraft |
||
404 | * |
||
405 | * @return APIRoleDraft if the authenticated user is not allowed to remove a policy |
||
406 | */ |
||
407 | View Code Duplication | public function removePolicyByRoleDraft(APIRoleDraft $roleDraft, PolicyDraft $policyDraft) |
|
421 | |||
422 | /** |
||
423 | * Updates the limitations of a policy. The module and function cannot be changed and |
||
424 | * the limitations are replaced by the ones in $roleUpdateStruct. |
||
425 | * |
||
426 | * @since 6.0 |
||
427 | * |
||
428 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a policy |
||
429 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy update |
||
430 | * struct or if limitation is not allowed on module/function |
||
431 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyUpdateStruct is not valid |
||
432 | * |
||
433 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
434 | * @param \eZ\Publish\API\Repository\Values\User\PolicyDraft $policy |
||
435 | * @param \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct $policyUpdateStruct |
||
436 | * |
||
437 | * @return \eZ\Publish\API\Repository\Values\User\PolicyDraft |
||
438 | */ |
||
439 | public function updatePolicyByRoleDraft(APIRoleDraft $roleDraft, PolicyDraft $policy, APIPolicyUpdateStruct $policyUpdateStruct) |
||
487 | |||
488 | /** |
||
489 | * Deletes the given RoleDraft. |
||
490 | * |
||
491 | * @since 6.0 |
||
492 | * |
||
493 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete this RoleDraft |
||
494 | * |
||
495 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
496 | */ |
||
497 | public function deleteRoleDraft(APIRoleDraft $roleDraft) |
||
510 | |||
511 | /** |
||
512 | * Publishes a given RoleDraft. |
||
513 | * |
||
514 | * @since 6.0 |
||
515 | * |
||
516 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to publish this RoleDraft |
||
517 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the role draft cannot be loaded |
||
518 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the role draft has no policies |
||
519 | * |
||
520 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft |
||
521 | */ |
||
522 | View Code Duplication | public function publishRoleDraft(APIRoleDraft $roleDraft) |
|
555 | |||
556 | /** |
||
557 | * Updates the name of the role. |
||
558 | * |
||
559 | * @deprecated since 6.0, use {@see updateRoleDraft} |
||
560 | * |
||
561 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a role |
||
562 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the name of the role already exists |
||
563 | * |
||
564 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
565 | * @param \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct $roleUpdateStruct |
||
566 | * |
||
567 | * @return \eZ\Publish\API\Repository\Values\User\Role |
||
568 | */ |
||
569 | public function updateRole(APIRole $role, RoleUpdateStruct $roleUpdateStruct) |
||
614 | |||
615 | /** |
||
616 | * Adds a new policy to the role. |
||
617 | * |
||
618 | * @deprecated since 6.0, use {@see addPolicyByRoleDraft} |
||
619 | * |
||
620 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to add a policy |
||
621 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy create |
||
622 | * struct or if limitation is not allowed on module/function |
||
623 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyCreateStruct is not valid |
||
624 | * |
||
625 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
626 | * @param \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct $policyCreateStruct |
||
627 | * |
||
628 | * @return \eZ\Publish\API\Repository\Values\User\Role |
||
629 | */ |
||
630 | View Code Duplication | public function addPolicy(APIRole $role, APIPolicyCreateStruct $policyCreateStruct) |
|
677 | |||
678 | /** |
||
679 | * Removes a policy from the role. |
||
680 | * |
||
681 | * @deprecated since 5.3, use {@link removePolicyByRoleDraft()} instead. |
||
682 | * |
||
683 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a policy |
||
684 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if policy does not belong to the given role |
||
685 | * |
||
686 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
687 | * @param \eZ\Publish\API\Repository\Values\User\Policy $policy the policy to remove from the role |
||
688 | * |
||
689 | * @return \eZ\Publish\API\Repository\Values\User\Role the updated role |
||
690 | */ |
||
691 | View Code Duplication | public function removePolicy(APIRole $role, APIPolicy $policy) |
|
705 | |||
706 | /** |
||
707 | * Deletes a policy. |
||
708 | * |
||
709 | * @deprecated since 6.0, use {@link removePolicyByRoleDraft()} instead. |
||
710 | * |
||
711 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a policy |
||
712 | * |
||
713 | * @param \eZ\Publish\API\Repository\Values\User\Policy $policy the policy to delete |
||
714 | */ |
||
715 | public function deletePolicy(APIPolicy $policy) |
||
723 | |||
724 | /** |
||
725 | * Deletes a policy. |
||
726 | * |
||
727 | * Used by {@link removePolicy()} and {@link deletePolicy()} |
||
728 | * |
||
729 | * @param APIPolicy $policy |
||
730 | * |
||
731 | * @throws \Exception |
||
732 | */ |
||
733 | protected function internalDeletePolicy(APIPolicy $policy) |
||
744 | |||
745 | /** |
||
746 | * Updates the limitations of a policy. The module and function cannot be changed and |
||
747 | * the limitations are replaced by the ones in $roleUpdateStruct. |
||
748 | * |
||
749 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a policy |
||
750 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy update |
||
751 | * struct or if limitation is not allowed on module/function |
||
752 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyUpdateStruct is not valid |
||
753 | * |
||
754 | * @param \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct $policyUpdateStruct |
||
755 | * @param \eZ\Publish\API\Repository\Values\User\Policy $policy |
||
756 | * |
||
757 | * @return \eZ\Publish\API\Repository\Values\User\Policy |
||
758 | */ |
||
759 | public function updatePolicy(APIPolicy $policy, APIPolicyUpdateStruct $policyUpdateStruct) |
||
802 | |||
803 | /** |
||
804 | * Loads a role for the given id. |
||
805 | * |
||
806 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
807 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given id was not found |
||
808 | * |
||
809 | * @param mixed $id |
||
810 | * |
||
811 | * @return \eZ\Publish\API\Repository\Values\User\Role |
||
812 | */ |
||
813 | View Code Duplication | public function loadRole($id) |
|
823 | |||
824 | /** |
||
825 | * Loads a role for the given identifier. |
||
826 | * |
||
827 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
828 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given name was not found |
||
829 | * |
||
830 | * @param string $identifier |
||
831 | * |
||
832 | * @return \eZ\Publish\API\Repository\Values\User\Role |
||
833 | */ |
||
834 | View Code Duplication | public function loadRoleByIdentifier($identifier) |
|
848 | |||
849 | /** |
||
850 | * Loads all roles. |
||
851 | * |
||
852 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read the roles |
||
853 | * |
||
854 | * @return \eZ\Publish\API\Repository\Values\User\Role[] |
||
855 | */ |
||
856 | View Code Duplication | public function loadRoles() |
|
871 | |||
872 | /** |
||
873 | * Deletes the given role. |
||
874 | * |
||
875 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete this role |
||
876 | * |
||
877 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
878 | */ |
||
879 | View Code Duplication | public function deleteRole(APIRole $role) |
|
880 | { |
||
881 | if ($this->repository->hasAccess('role', 'delete') !== true) { |
||
882 | throw new UnauthorizedException('role', 'delete'); |
||
883 | } |
||
884 | |||
885 | $loadedRole = $this->loadRole($role->id); |
||
886 | |||
887 | $this->repository->beginTransaction(); |
||
888 | try { |
||
889 | $this->userHandler->deleteRole($loadedRole->id); |
||
890 | $this->repository->commit(); |
||
891 | } catch (Exception $e) { |
||
892 | $this->repository->rollback(); |
||
893 | throw $e; |
||
894 | } |
||
895 | } |
||
896 | |||
897 | /** |
||
898 | * Loads all policies from roles which are assigned to a user or to user groups to which the user belongs. |
||
899 | * |
||
900 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user with the given id was not found |
||
901 | * |
||
902 | * @param mixed $userId |
||
903 | * |
||
904 | * @return \eZ\Publish\API\Repository\Values\User\Policy[] |
||
905 | */ |
||
906 | public function loadPoliciesByUserId($userId) |
||
921 | |||
922 | /** |
||
923 | * Assigns a role to the given user group. |
||
924 | * |
||
925 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign a role |
||
926 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if $roleLimitation is not valid |
||
927 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If assignment already exists |
||
928 | * |
||
929 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
930 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
931 | * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation) |
||
932 | */ |
||
933 | View Code Duplication | public function assignRoleToUserGroup(APIRole $role, UserGroup $userGroup, RoleLimitation $roleLimitation = null) |
|
969 | |||
970 | /** |
||
971 | * removes a role from the given user group. |
||
972 | * |
||
973 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role |
||
974 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the role is not assigned to the given user group |
||
975 | * |
||
976 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
977 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
978 | */ |
||
979 | View Code Duplication | public function unassignRoleFromUserGroup(APIRole $role, UserGroup $userGroup) |
|
1010 | |||
1011 | /** |
||
1012 | * Assigns a role to the given user. |
||
1013 | * |
||
1014 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign a role |
||
1015 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if $roleLimitation is not valid |
||
1016 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If assignment already exists |
||
1017 | * |
||
1018 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
1019 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
1020 | * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation) |
||
1021 | */ |
||
1022 | View Code Duplication | public function assignRoleToUser(APIRole $role, User $user, RoleLimitation $roleLimitation = null) |
|
1058 | |||
1059 | /** |
||
1060 | * removes a role from the given user. |
||
1061 | * |
||
1062 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role |
||
1063 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the role is not assigned to the user |
||
1064 | * |
||
1065 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
1066 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
1067 | */ |
||
1068 | View Code Duplication | public function unassignRoleFromUser(APIRole $role, User $user) |
|
1099 | |||
1100 | /** |
||
1101 | * Removes the given role assignment. |
||
1102 | * |
||
1103 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role assignment |
||
1104 | * |
||
1105 | * @param \eZ\Publish\API\Repository\Values\User\RoleAssignment $roleAssignment |
||
1106 | */ |
||
1107 | View Code Duplication | public function removeRoleAssignment(RoleAssignment $roleAssignment) |
|
1108 | { |
||
1109 | if ($this->repository->canUser('role', 'assign', $roleAssignment) !== true) { |
||
1110 | throw new UnauthorizedException('role', 'assign'); |
||
1111 | } |
||
1112 | |||
1113 | $spiRoleAssignment = $this->userHandler->loadRoleAssignment($roleAssignment->id); |
||
1114 | |||
1115 | $this->repository->beginTransaction(); |
||
1116 | try { |
||
1117 | $this->userHandler->removeRoleAssignment($spiRoleAssignment->id); |
||
1118 | $this->repository->commit(); |
||
1119 | } catch (Exception $e) { |
||
1120 | $this->repository->rollback(); |
||
1121 | throw $e; |
||
1122 | } |
||
1123 | } |
||
1124 | |||
1125 | /** |
||
1126 | * Loads a role assignment for the given id. |
||
1127 | * |
||
1128 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role |
||
1129 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the role assignment was not found |
||
1130 | * |
||
1131 | * @param mixed $roleAssignmentId |
||
1132 | * |
||
1133 | * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment |
||
1134 | */ |
||
1135 | public function loadRoleAssignment($roleAssignmentId) |
||
1170 | |||
1171 | /** |
||
1172 | * Returns the assigned user and user groups to this role. |
||
1173 | * |
||
1174 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read a role |
||
1175 | * |
||
1176 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
1177 | * |
||
1178 | * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment[] |
||
1179 | */ |
||
1180 | public function getRoleAssignments(APIRole $role) |
||
1216 | |||
1217 | /** |
||
1218 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUser() |
||
1219 | */ |
||
1220 | public function getRoleAssignmentsForUser(User $user, $inherited = false) |
||
1248 | |||
1249 | /** |
||
1250 | * Returns the roles assigned to the given user group. |
||
1251 | * |
||
1252 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read a role |
||
1253 | * |
||
1254 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
1255 | * |
||
1256 | * @return \eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment[] |
||
1257 | */ |
||
1258 | public function getRoleAssignmentsForUserGroup(UserGroup $userGroup) |
||
1277 | |||
1278 | /** |
||
1279 | * Instantiates a role create class. |
||
1280 | * |
||
1281 | * @param string $name |
||
1282 | * |
||
1283 | * @return \eZ\Publish\API\Repository\Values\User\RoleCreateStruct |
||
1284 | */ |
||
1285 | public function newRoleCreateStruct($name) |
||
1294 | |||
1295 | /** |
||
1296 | * Instantiates a policy create class. |
||
1297 | * |
||
1298 | * @param string $module |
||
1299 | * @param string $function |
||
1300 | * |
||
1301 | * @return \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct |
||
1302 | */ |
||
1303 | public function newPolicyCreateStruct($module, $function) |
||
1313 | |||
1314 | /** |
||
1315 | * Instantiates a policy update class. |
||
1316 | * |
||
1317 | * @return \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct |
||
1318 | */ |
||
1319 | public function newPolicyUpdateStruct() |
||
1327 | |||
1328 | /** |
||
1329 | * Instantiates a policy update class. |
||
1330 | * |
||
1331 | * @return \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct |
||
1332 | */ |
||
1333 | public function newRoleUpdateStruct() |
||
1337 | |||
1338 | /** |
||
1339 | * Returns the LimitationType registered with the given identifier. |
||
1340 | * |
||
1341 | * Returns the correct implementation of API Limitation value object |
||
1342 | * based on provided identifier |
||
1343 | * |
||
1344 | * @param string $identifier |
||
1345 | * |
||
1346 | * @return \eZ\Publish\SPI\Limitation\Type |
||
1347 | * |
||
1348 | * @throws \RuntimeException if there is no LimitationType with $identifier |
||
1349 | */ |
||
1350 | public function getLimitationType($identifier) |
||
1354 | |||
1355 | /** |
||
1356 | * Returns the LimitationType's assigned to a given module/function. |
||
1357 | * |
||
1358 | * Typically used for: |
||
1359 | * - Internal validation limitation value use on Policies |
||
1360 | * - Role admin gui for editing policy limitations incl list limitation options via valueSchema() |
||
1361 | * |
||
1362 | * @param string $module Legacy name of "controller", it's a unique identifier like "content" |
||
1363 | * @param string $function Legacy name of a controller "action", it's a unique within the controller like "read" |
||
1364 | * |
||
1365 | * @return \eZ\Publish\SPI\Limitation\Type[] |
||
1366 | * |
||
1367 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If module/function to limitation type mapping |
||
1368 | * refers to a non existing identifier. |
||
1369 | */ |
||
1370 | public function getLimitationTypesByModuleFunction($module, $function) |
||
1391 | |||
1392 | /** |
||
1393 | * Validates Policies and Limitations in Role create struct. |
||
1394 | * |
||
1395 | * @uses validatePolicy() |
||
1396 | * |
||
1397 | * @param \eZ\Publish\API\Repository\Values\User\RoleCreateStruct $roleCreateStruct |
||
1398 | * |
||
1399 | * @return \eZ\Publish\Core\FieldType\ValidationError[][][] |
||
1400 | */ |
||
1401 | protected function validateRoleCreateStruct(APIRoleCreateStruct $roleCreateStruct) |
||
1418 | |||
1419 | /** |
||
1420 | * Validates Policy context: Limitations on a module and function. |
||
1421 | * |
||
1422 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If the same limitation is repeated or if |
||
1423 | * limitation is not allowed on module/function |
||
1424 | * |
||
1425 | * @param string $module |
||
1426 | * @param string $function |
||
1427 | * @param \eZ\Publish\API\Repository\Values\User\Limitation[] $limitations |
||
1428 | * |
||
1429 | * @return \eZ\Publish\Core\FieldType\ValidationError[][] |
||
1430 | */ |
||
1431 | protected function validatePolicy($module, $function, array $limitations) |
||
1456 | |||
1457 | /** |
||
1458 | * Validate that assignments not already exists and filter validations against existing. |
||
1459 | * |
||
1460 | * @param mixed $contentId |
||
1461 | * @param SPIRole $spiRole |
||
1462 | * @param array|null $limitation |
||
1463 | * |
||
1464 | * @return array[]|null Filtered version of $limitation |
||
1465 | * |
||
1466 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If assignment already exists |
||
1467 | */ |
||
1468 | protected function checkAssignmentAndFilterLimitationValues($contentId, SPIRole $spiRole, array $limitation = null) |
||
1510 | } |
||
1511 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.