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/ObjectMembershipWithMapHandler.php +36 -5 2.3.132.2.3 View file →
@@ -1,5 +1,18 @@
1 1 <?php
2 +/**
3 + * MembershipWithMapHandler.php
4 + *
5 + * The MembershipWithMapHandler 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;
@@ -8,24 +21,35 @@
8 21 use UserAccessManager\Object\ObjectMapHandler;
9 22 use UserAccessManager\UserGroup\AbstractUserGroup;
10 23 use UserAccessManager\UserGroup\AssignmentInformation;
11 24
25 +/**
26 + * Class MembershipWithMapHandler
27 + *
28 + * @package UserAccessManager\UserGroup
29 + */
12 30 abstract class ObjectMembershipWithMapHandler extends ObjectMembershipHandler
13 31 {
14 32 /**
15 33 * Returns the map.
16 - * @return array
34 + * @return array
17 35 */
18 36 abstract protected function getMap(): array;
19 37
20 38 /**
39 + * Uses a map function to resolve the recursive membership.
40 + * @param AbstractUserGroup $userGroup
41 + * @param bool $lockRecursive
42 + * @param int|string $objectId
43 + * @param null|AssignmentInformation $assignmentInformation
44 + * @return bool
21 45 * @throws Exception
22 46 */
23 47 protected function getMembershipByMap(
24 48 AbstractUserGroup $userGroup,
25 49 bool $lockRecursive,
26 - int|string|null $objectId,
27 - ?AssignmentInformation &$assignmentInformation = null
50 + $objectId,
51 + &$assignmentInformation = null
28 52 ): bool {
29 53 // Reset value to prevent errors
30 54 $recursiveMembership = [];
31 55
@@ -30,9 +54,10 @@
30 54 $recursiveMembership = [];
31 55
32 56 if ($lockRecursive === true) {
33 57 $map = $this->getMap();
34 - $generalMap = $map[ObjectMapHandler::TREE_MAP_PARENTS][$this->generalObjectType] ?? [];
58 + $generalMap = isset($map[ObjectMapHandler::TREE_MAP_PARENTS][$this->generalObjectType]) ?
59 + $map[ObjectMapHandler::TREE_MAP_PARENTS][$this->generalObjectType] : [];
35 60
36 61 if (isset($generalMap[$objectId]) === true) {
37 62 foreach ($generalMap[$objectId] as $parentId => $type) {
38 63 $isObjectMember = $userGroup->isObjectMember(
@@ -52,8 +77,13 @@
52 77 return $this->checkAccessWithRecursiveMembership($isMember, $recursiveMembership, $assignmentInformation);
53 78 }
54 79
55 80 /**
81 + * Returns the objects by the given type including the children.
82 + * @param AbstractUserGroup $userGroup
83 + * @param bool $lockRecursive
84 + * @param string $objectType
85 + * @return array
56 86 * @throws Exception
57 87 */
58 88 protected function getFullObjectsByMap(AbstractUserGroup $userGroup, bool $lockRecursive, string $objectType): array
59 89 {
@@ -60,9 +90,10 @@
60 90 $objects = $this->getSimpleAssignedObjects($userGroup, $objectType);
61 91
62 92 if ($lockRecursive === true) {
63 93 $map = $this->getMap();
64 - $map = $map[ObjectMapHandler::TREE_MAP_CHILDREN][$objectType] ?? [];
94 + $map = isset($map[ObjectMapHandler::TREE_MAP_CHILDREN][$objectType]) ?
95 + $map[ObjectMapHandler::TREE_MAP_CHILDREN][$objectType] : [];
65 96 $map = array_intersect_key($map, $objects);
66 97
67 98 foreach ($map as $childrenIds) {
68 99 foreach ($childrenIds as $parentId => $type) {