]> git.mxchange.org Git - friendica.git/blob - src/Security/PermissionSet/Factory/PermissionSet.php
"getStyledURL" is now public
[friendica.git] / src / Security / PermissionSet / Factory / PermissionSet.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Security\PermissionSet\Factory;
23
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;
29
30 class PermissionSet extends BaseFactory implements ICanCreateFromTableRow
31 {
32         /** @var ACLFormatter */
33         protected $formatter;
34
35         public function __construct(LoggerInterface $logger, ACLFormatter $formatter)
36         {
37                 parent::__construct($logger);
38
39                 $this->formatter = $formatter;
40         }
41
42         /**
43          * @inheritDoc
44          */
45         public function createFromTableRow(array $row): Entity\PermissionSet
46         {
47                 return new Entity\PermissionSet(
48                         $row['uid'],
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'] ?? ''),
53                         $row['id'] ?? null
54                 );
55         }
56
57         /**
58          * Creates a new PermissionSet based on it's fields
59          *
60          * @param int    $uid
61          * @param string $allow_cid
62          * @param string $allow_gid
63          * @param string $deny_cid
64          * @param string $deny_gid
65          *
66          * @return Entity\PermissionSet
67          */
68         public function createFromString(
69                 int $uid,
70                 string $allow_cid = '',
71                 string $allow_gid = '',
72                 string $deny_cid = '',
73                 string $deny_gid = '',
74                 int $id = null): Entity\PermissionSet
75         {
76                 return $this->createFromTableRow([
77                         'uid'       => $uid,
78                         'allow_cid' => $allow_cid,
79                         'allow_gid' => $allow_gid,
80                         'deny_cid'  => $deny_cid,
81                         'deny_gid'  => $deny_gid,
82                         'id'        => $id,
83                 ]);
84         }
85 }