]> git.mxchange.org Git - friendica.git/blob - tests/Util/SampleStorageBackend.php
- Fixing SystemResource
[friendica.git] / tests / Util / SampleStorageBackend.php
1 <?php
2
3 namespace Friendica\Test\Util;
4
5 use Friendica\Model\Storage\IStorage;
6
7 use Friendica\Core\L10n\L10n;
8
9 /**
10  * A backend storage example class
11  */
12 class SampleStorageBackend implements IStorage
13 {
14         const NAME = 'Sample Storage';
15
16         /** @var L10n */
17         private $l10n;
18
19         /** @var array */
20         private $options = [
21                 'filename' => [
22                         'input',    // will use a simple text input
23                         'The file to return',    // the label
24                         'sample',    // the current value
25                         'Enter the path to a file', // the help text
26                         // no extra data for 'input' type..
27                 ],
28         ];
29         /** @var array Just save the data in memory */
30         private $data = [];
31
32         /**
33          * SampleStorageBackend constructor.
34          *
35          * @param L10n $l10n The configuration of Friendica
36          *
37          * You can add here every dynamic class as dependency you like and add them to a private field
38          * Friendica automatically creates these classes and passes them as argument to the constructor
39          */
40         public function __construct(L10n $l10n)
41         {
42                 $this->l10n = $l10n;
43         }
44
45         public function get(string $reference)
46         {
47                 // we return always the same image data. Which file we load is defined by
48                 // a config key
49                 return $this->data[$reference] ?? null;
50         }
51
52         public function put(string $data, string $reference = '')
53         {
54                 if ($reference === '') {
55                         $reference = 'sample';
56                 }
57
58                 $this->data[$reference] = $data;
59
60                 return $reference;
61         }
62
63         public function delete(string $reference)
64         {
65                 if (isset($this->data[$reference])) {
66                         unset($this->data[$reference]);
67                 }
68
69                 return true;
70         }
71
72         public function getOptions()
73         {
74                 return $this->options;
75         }
76
77         public function saveOptions(array $data)
78         {
79                 $this->options = $data;
80
81                 // no errors, return empty array
82                 return $this->options;
83         }
84
85         public function __toString()
86         {
87                 return self::NAME;
88         }
89
90         public static function getName()
91         {
92                 return self::NAME;
93         }
94 }