PluginProbe
User Access Manager / 2.2.3
User Access Manager v2.2.3
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/ObjectMembership/RoleMembershipHandler.php +57 -8 2.3.132.2.3 View file →
@@ -1,5 +1,18 @@
1 1 <?php
2 +/**
3 + * RoleMembershipHandler.php
4 + *
5 + * The RoleMembershipHandler class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 + * @copyright 2008-2017 Alexander Schneider
11 + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 + * @version SVN: $id$
13 + * @link http://wordpress.org/extend/plugins/user-access-manager/
14 + */
2 15
3 16 declare(strict_types=1);
4 17
5 18 namespace UserAccessManager\ObjectMembership;
@@ -10,23 +23,44 @@
10 23 use UserAccessManager\UserGroup\AssignmentInformation;
11 24 use UserAccessManager\UserGroup\AssignmentInformationFactory;
12 25 use UserAccessManager\Wrapper\Wordpress;
13 26
27 +/**
28 + * Class RoleMembershipHandler
29 + *
30 + * @package UserAccessManager\UserGroup
31 + */
14 32 class RoleMembershipHandler extends ObjectMembershipHandler
15 33 {
16 - protected ?string $generalObjectType = ObjectHandler::GENERAL_ROLE_OBJECT_TYPE;
34 + /**
35 + * @var Wordpress
36 + */
37 + private $wordpress;
17 38
18 39 /**
19 - * @throws Exception
40 + * @var string
20 41 */
21 - public function __construct(
22 - AssignmentInformationFactory $assignmentInformationFactory,
23 - private Wordpress $wordpress
24 - ) {
42 + protected $generalObjectType = ObjectHandler::GENERAL_ROLE_OBJECT_TYPE;
43 +
44 + /**
45 + * RoleMembershipHandler constructor.
46 + * @param AssignmentInformationFactory $assignmentInformationFactory
47 + * @param Wordpress $wordpress
48 + * @throws Exception
49 + */
50 + public function __construct(AssignmentInformationFactory $assignmentInformationFactory, Wordpress $wordpress)
51 + {
25 52 parent::__construct($assignmentInformationFactory);
53 + $this->wordpress = $wordpress;
26 54 }
27 55
28 - public function getObjectName(int|string|null $objectId, string &$typeName = ''): int|string
56 + /**
57 + * Returns the object and type name.
58 + * @param int|string $objectId
59 + * @param string $typeName
60 + * @return int|string
61 + */
62 + public function getObjectName($objectId, &$typeName = '')
29 63 {
30 64 $typeName = $this->generalObjectType;
31 65 $roles = $this->wordpress->getRoles()->role_names;
32 66 return (isset($roles[$objectId]) === true) ? $roles[$objectId] : $objectId;
@@ -31,12 +65,20 @@
31 65 $roles = $this->wordpress->getRoles()->role_names;
32 66 return (isset($roles[$objectId]) === true) ? $roles[$objectId] : $objectId;
33 67 }
34 68
69 + /**
70 + * Checks if the role is a member of the user group.
71 + * @param AbstractUserGroup $userGroup
72 + * @param bool $lockRecursive
73 + * @param int|string $objectId
74 + * @param null|AssignmentInformation $assignmentInformation
75 + * @return bool
76 + */
35 77 public function isMember(
36 78 AbstractUserGroup $userGroup,
37 79 bool $lockRecursive,
38 - int|string|null $objectId,
80 + $objectId,
39 81 ?AssignmentInformation &$assignmentInformation = null
40 82 ): bool {
41 83 $isMember = $userGroup->isObjectAssignedToGroup(
42 84 $this->generalObjectType,
@@ -47,8 +89,15 @@
47 89
48 90 return $isMember;
49 91 }
50 92
93 + /**
94 + * Returns the full role objects.
95 + * @param AbstractUserGroup $userGroup
96 + * @param bool $lockRecursive
97 + * @param null $objectType
98 + * @return array
99 + */
51 100 public function getFullObjects(AbstractUserGroup $userGroup, bool $lockRecursive, $objectType = null): array
52 101 {
53 102 $objectType = ($objectType === null) ? $this->generalObjectType : $objectType;
54 103