]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/ACLFormatter.php
bump version 2023.12
[friendica.git] / src / Util / ACLFormatter.php
index 352c914bcf54222953eefaebd243003b71531d1f..cd398fc280a419c314fe6b2e7a0a5af7ae299cf6 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -21,7 +21,7 @@
 
 namespace Friendica\Util;
 
-use Friendica\Model\Group;
+use Friendica\Model\Circle;
 
 /**
  * Util class for ACL formatting
@@ -29,22 +29,22 @@ use Friendica\Model\Group;
 final class ACLFormatter
 {
        /**
-        * Turn user/group ACLs stored as angle bracketed text into arrays
+        * Turn user/circle ACLs stored as angle bracketed text into arrays
         *
         * @param string|null $acl_string A angle-bracketed list of IDs
         *
         * @return array The array based on the IDs (empty in case there is no list)
         */
-       public function expand(string $acl_string = null)
+       public function expand(string $acl_string = null): array
        {
                // In case there is no ID list, return empty array (=> no ACL set)
-               if (!isset($acl_string)) {
+               if (empty($acl_string)) {
                        return [];
                }
 
                // turn string array of angle-bracketed elements into numeric array
                // e.g. "<1><2><3>" => array(1,2,3);
-               preg_match_all('/<(' . Group::FOLLOWERS . '|'. Group::MUTUALS . '|[0-9]+)>/', $acl_string, $matches, PREG_PATTERN_ORDER);
+               preg_match_all('/<(' . Circle::FOLLOWERS . '|'. Circle::MUTUALS . '|[0-9]+)>/', $acl_string, $matches, PREG_PATTERN_ORDER);
 
                return $matches[1];
        }
@@ -55,7 +55,7 @@ final class ACLFormatter
         * @param string|null $acl_string
         * @return string
         */
-       public function sanitize(string $acl_string = null)
+       public function sanitize(string $acl_string = null): string
        {
                if (empty($acl_string)) {
                        return '';
@@ -86,7 +86,7 @@ final class ACLFormatter
                if (intval($item)) {
                        $item = '<' . intval($item) . '>';
                // The item is a allowed ACL character
-               } elseif (in_array($item, [Group::FOLLOWERS, Group::MUTUALS])) {
+               } elseif (in_array($item, [Circle::FOLLOWERS, Circle::MUTUALS])) {
                        $item = '<' . $item . '>';
                // The item is already a ACL string
                } elseif (preg_match('/<\d+?>/', $item)) {
@@ -107,10 +107,13 @@ final class ACLFormatter
         *
         * @return string
         */
-       function toString($permissions) {
+       function toString($permissions): string
+       {
                $return = '';
                if (is_array($permissions)) {
                        $item = $permissions;
+               } elseif (empty($permissions)) {
+                       return '';
                } else {
                        $item = explode(',', $permissions);
                }