3 namespace Friendica\Test\Util;
5 use Friendica\Core\Hook;
6 use Friendica\Model\Storage\IStorage;
8 use Friendica\Core\L10n;
11 * A backend storage example class
13 class SampleStorageBackend implements IStorage
15 const NAME = 'Sample Storage';
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..
30 /** @var array Just save the data in memory */
34 * SampleStorageBackend constructor.
36 * @param L10n $l10n The configuration of Friendica
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
41 public function __construct(L10n $l10n)
46 public function get(string $reference)
48 // we return always the same image data. Which file we load is defined by
50 return $this->data[$reference] ?? null;
53 public function put(string $data, string $reference = '')
55 if ($reference === '') {
56 $reference = 'sample';
59 $this->data[$reference] = $data;
64 public function delete(string $reference)
66 if (isset($this->data[$reference])) {
67 unset($this->data[$reference]);
73 public function getOptions()
75 return $this->options;
78 public function saveOptions(array $data)
80 $this->options = $data;
82 // no errors, return empty array
83 return $this->options;
86 public function __toString()
91 public static function getName()
97 * This one is a hack to register this class to the hook
99 public static function registerHook()
101 Hook::register('storage_instance', __DIR__ . '/SampleStorageBackendInstance.php', 'create_instance');