3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Test\Util;
24 use Friendica\Core\Hook;
25 use Friendica\Model\Storage\IStorage;
27 use Friendica\Core\L10n;
30 * A backend storage example class
32 class SampleStorageBackend implements IStorage
34 const NAME = 'Sample Storage';
42 'input', // will use a simple text input
43 'The file to return', // the label
44 'sample', // the current value
45 'Enter the path to a file', // the help text
46 // no extra data for 'input' type..
49 /** @var array Just save the data in memory */
53 * SampleStorageBackend constructor.
55 * @param L10n $l10n The configuration of Friendica
57 * You can add here every dynamic class as dependency you like and add them to a private field
58 * Friendica automatically creates these classes and passes them as argument to the constructor
60 public function __construct(L10n $l10n)
65 public function get(string $reference)
67 // we return always the same image data. Which file we load is defined by
69 return $this->data[$reference] ?? null;
72 public function put(string $data, string $reference = '')
74 if ($reference === '') {
75 $reference = 'sample';
78 $this->data[$reference] = $data;
83 public function delete(string $reference)
85 if (isset($this->data[$reference])) {
86 unset($this->data[$reference]);
92 public function getOptions()
94 return $this->options;
97 public function saveOptions(array $data)
99 $this->options = $data;
101 // no errors, return empty array
102 return $this->options;
105 public function __toString()
110 public static function getName()
116 * This one is a hack to register this class to the hook
118 public static function registerHook()
120 Hook::register('storage_instance', __DIR__ . '/SampleStorageBackendInstance.php', 'create_instance');