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