]> git.mxchange.org Git - friendica.git/blob - src/Model/Storage/SystemResource.php
Detection of local requests
[friendica.git] / src / Model / Storage / SystemResource.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 \BadMethodCallException;
25
26 /**
27  * System resource storage class
28  *
29  * This class is used to load system resources, like images.
30  * Is not intended to be selectable by admins as default storage class.
31  */
32 class SystemResource implements IStorage
33 {
34         const NAME = 'SystemResource';
35
36         // Valid folders to look for resources
37         const VALID_FOLDERS = ["images"];
38
39         /**
40          * @inheritDoc
41          */
42         public function get(string $filename)
43         {
44                 $folder = dirname($filename);
45                 if (!in_array($folder, self::VALID_FOLDERS)) {
46                         return "";
47                 }
48                 if (!file_exists($filename)) {
49                         return "";
50                 }
51                 return file_get_contents($filename);
52         }
53
54         /**
55          * @inheritDoc
56          */
57         public function put(string $data, string $filename = '')
58         {
59                 throw new BadMethodCallException();
60         }
61
62         public function delete(string $filename)
63         {
64                 throw new BadMethodCallException();
65         }
66
67         /**
68          * @inheritDoc
69          */
70         public function getOptions()
71         {
72                 return [];
73         }
74
75         /**
76          * @inheritDoc
77          */
78         public function saveOptions(array $data)
79         {
80                 return [];
81         }
82
83         /**
84          * @inheritDoc
85          */
86         public function __toString()
87         {
88                 return self::NAME;
89         }
90
91         /**
92          * @inheritDoc
93          */
94         public static function getName()
95         {
96                 return self::NAME;
97         }
98 }