From 86faceb94f7d33d0178d5ae21571d4436bbbafb6 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 15 Nov 2019 12:27:55 +0200 Subject: [PATCH] Deprecated `Grav\Common\User\Group` in favor of `$grav['user_groups']`, which contains Flex UserGroup collection --- CHANGELOG.md | 2 ++ .../Grav/Common/Flex/UserGroups/UserGroup.php | 3 ++- system/src/Grav/Common/User/Group.php | 21 ++++++++++++--- .../User/Interfaces/AuthorizeInterface.php | 26 +++++++++++++++++++ .../User/Interfaces/UserGroupInterface.php | 18 +++++++++++++ .../Common/User/Interfaces/UserInterface.php | 11 +------- system/src/Grav/Common/User/User.php | 2 +- 7 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 system/src/Grav/Common/User/Interfaces/AuthorizeInterface.php create mode 100644 system/src/Grav/Common/User/Interfaces/UserGroupInterface.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f1341c7a..6704b1374 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ * Added new `-r ` option for Scheduler CLI command to force-run a job [#2720](https://github.com/getgrav/grav/issues/2720) * Added `Utils::isAssoc()` and `Utils::isNegative()` helper methods * Changed `UserInterface::authorize()` to return `null` having the same meaning as `false` if access is denied because of no matching rule + * Moved all Flex type classes under `Grav\Common\Flex` + * Deprecated `Grav\Common\User\Group` in favor of `$grav['user_groups']`, which contains Flex UserGroup collection 1. [](#improved) * Improved twig `|array` filter to work with iterators and objects with `toArray()` method * Updated Flex `SimpleStorage` code to feature match the other storages diff --git a/system/src/Grav/Common/Flex/UserGroups/UserGroup.php b/system/src/Grav/Common/Flex/UserGroups/UserGroup.php index fb2693e5c..6ea0f5bfa 100644 --- a/system/src/Grav/Common/Flex/UserGroups/UserGroup.php +++ b/system/src/Grav/Common/Flex/UserGroups/UserGroup.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Grav\Common\Flex\UserGroups; use Grav\Common\User\Access; +use Grav\Common\User\Interfaces\UserGroupInterface; use Grav\Framework\Flex\FlexObject; use Grav\Framework\Flex\Traits\FlexAuthorizeTrait; @@ -23,7 +24,7 @@ use Grav\Framework\Flex\Traits\FlexAuthorizeTrait; * @property string $groupname * @property Access $access */ -class UserGroup extends FlexObject +class UserGroup extends FlexObject implements UserGroupInterface { use FlexAuthorizeTrait; diff --git a/system/src/Grav/Common/User/Group.php b/system/src/Grav/Common/User/Group.php index c9e745eb6..ff3f69548 100644 --- a/system/src/Grav/Common/User/Group.php +++ b/system/src/Grav/Common/User/Group.php @@ -16,15 +16,21 @@ use Grav\Common\File\CompiledYamlFile; use Grav\Common\Grav; use Grav\Common\Utils; +/** + * @deprecated 1.7 Use $grav['user_groups'] instead of this class. In type hints, please use UserGroupInterface. + */ class Group extends Data { /** * Get the groups list * * @return array + * @deprecated 1.7, use $grav['user_groups'] Flex UserGroupCollection instead */ private static function groups() { + user_error(__METHOD__ . '() is deprecated since Grav 1.7, use $grav[\'user_groups\'] Flex UserGroupCollection instead', E_USER_DEPRECATED); + return Grav::instance()['config']->get('groups', []); } @@ -32,9 +38,12 @@ class Group extends Data * Get the groups list * * @return array + * @deprecated 1.7, use $grav['user_groups'] Flex UserGroupCollection instead */ public static function groupNames() { + user_error(__METHOD__ . '() is deprecated since Grav 1.7, use $grav[\'user_groups\'] Flex UserGroupCollection instead', E_USER_DEPRECATED); + $groups = []; foreach (static::groups() as $groupname => $group) { @@ -48,11 +57,13 @@ class Group extends Data * Checks if a group exists * * @param string $groupname - * * @return bool + * @deprecated 1.7, use $grav['user_groups'] Flex UserGroupCollection instead */ public static function groupExists($groupname) { + user_error(__METHOD__ . '() is deprecated since Grav 1.7, use $grav[\'user_groups\'] Flex UserGroupCollection instead', E_USER_DEPRECATED); + return isset(self::groups()[$groupname]); } @@ -60,11 +71,13 @@ class Group extends Data * Get a group by name * * @param string $groupname - * * @return object + * @deprecated 1.7, use $grav['user_groups'] Flex UserGroupCollection instead */ public static function load($groupname) { + user_error(__METHOD__ . '() is deprecated since Grav 1.7, use $grav[\'user_groups\'] Flex UserGroupCollection instead', E_USER_DEPRECATED); + $groups = self::groups(); $content = $groups[$groupname] ?? []; @@ -125,11 +138,13 @@ class Group extends Data * Remove a group * * @param string $groupname - * * @return bool True if the action was performed + * @deprecated 1.7, use $grav['user_groups'] Flex UserGroupCollection instead */ public static function remove($groupname) { + user_error(__METHOD__ . '() is deprecated since Grav 1.7, use $grav[\'user_groups\'] Flex UserGroupCollection instead', E_USER_DEPRECATED); + $grav = Grav::instance(); /** @var Config $config */ diff --git a/system/src/Grav/Common/User/Interfaces/AuthorizeInterface.php b/system/src/Grav/Common/User/Interfaces/AuthorizeInterface.php new file mode 100644 index 000000000..8cc206217 --- /dev/null +++ b/system/src/Grav/Common/User/Interfaces/AuthorizeInterface.php @@ -0,0 +1,26 @@ +