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