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