3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Security\PermissionSet\Factory;
24 use Friendica\BaseFactory;
25 use Friendica\Capabilities\ICanCreateFromTableRow;
26 use Friendica\Security\PermissionSet\Entity;
27 use Friendica\Util\ACLFormatter;
28 use Psr\Log\LoggerInterface;
30 class PermissionSet extends BaseFactory implements ICanCreateFromTableRow
32 /** @var ACLFormatter */
35 public function __construct(LoggerInterface $logger, ACLFormatter $formatter)
37 parent::__construct($logger);
39 $this->formatter = $formatter;
45 public function createFromTableRow(array $row): Entity\PermissionSet
47 return new Entity\PermissionSet(
49 $this->formatter->expand($row['allow_cid'] ?? ''),
50 $this->formatter->expand($row['allow_gid'] ?? ''),
51 $this->formatter->expand($row['deny_cid'] ?? ''),
52 $this->formatter->expand($row['deny_gid'] ?? ''),
58 * Creates a new PermissionSet based on it's fields
61 * @param string $allow_cid
62 * @param string $allow_gid
63 * @param string $deny_cid
64 * @param string $deny_gid
66 * @return Entity\PermissionSet
68 public function createFromString(
70 string $allow_cid = '',
71 string $allow_gid = '',
72 string $deny_cid = '',
73 string $deny_gid = '',
74 int $id = null): Entity\PermissionSet
76 return $this->createFromTableRow([
78 'allow_cid' => $allow_cid,
79 'allow_gid' => $allow_gid,
80 'deny_cid' => $deny_cid,
81 'deny_gid' => $deny_gid,