]> git.mxchange.org Git - friendica.git/blob - src/Model/Storage/FilesystemConfig.php
Account for the PUBLIC value for id parameter in Depository\PermissionSet::selectOneById
[friendica.git] / src / Model / Storage / FilesystemConfig.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, 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\Model\Storage;
23
24 use Friendica\Core\Config\IConfig;
25 use Friendica\Core\L10n;
26
27 /**
28  * Filesystem based storage backend configuration
29  */
30 class FilesystemConfig implements IStorageConfiguration
31 {
32         // Default base folder
33         const DEFAULT_BASE_FOLDER = 'storage';
34
35         /** @var IConfig */
36         private $config;
37
38         /** @var string */
39         private $storagePath;
40
41         /** @var L10n */
42         private $l10n;
43
44         /**
45          * Returns the current storage path
46          *
47          * @return string
48          */
49         public function getStoragePath(): string
50         {
51                 return $this->storagePath;
52         }
53
54         /**
55          * Filesystem constructor.
56          *
57          * @param IConfig         $config
58          * @param L10n            $l10n
59          */
60         public function __construct(IConfig $config, L10n $l10n)
61         {
62                 $this->config = $config;
63                 $this->l10n   = $l10n;
64
65                 $path              = $this->config->get('storage', 'filesystem_path', self::DEFAULT_BASE_FOLDER);
66                 $this->storagePath = rtrim($path, '/');
67         }
68
69         /**
70          * @inheritDoc
71          */
72         public function getOptions(): array
73         {
74                 return [
75                         'storagepath' => [
76                                 'input',
77                                 $this->l10n->t('Storage base path'),
78                                 $this->storagePath,
79                                 $this->l10n->t('Folder where uploaded files are saved. For maximum security, This should be a path outside web server folder tree')
80                         ]
81                 ];
82         }
83
84         /**
85          * @inheritDoc
86          */
87         public function saveOptions(array $data): array
88         {
89                 $storagePath = $data['storagepath'] ?? '';
90                 if ($storagePath === '' || !is_dir($storagePath)) {
91                         return [
92                                 'storagepath' => $this->l10n->t('Enter a valid existing folder')
93                         ];
94                 };
95                 $this->config->set('storage', 'filesystem_path', $storagePath);
96                 $this->storagePath = $storagePath;
97                 return [];
98         }
99 }