3 namespace Friendica\Test\Util;
6 use Friendica\Core\Hook;
7 use Friendica\Model\Storage\IStorage;
9 use Friendica\Core\L10n\L10n;
10 use Mockery\MockInterface;
13 * A backend storage example class
15 class SampleStorageBackend implements IStorage
17 const NAME = 'Sample Storage';
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..
32 /** @var array Just save the data in memory */
36 * SampleStorageBackend constructor.
38 * @param L10n $l10n The configuration of Friendica
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
43 public function __construct(L10n $l10n)
48 public function get(string $reference)
50 // we return always the same image data. Which file we load is defined by
52 return $this->data[$reference] ?? null;
55 public function put(string $data, string $reference = '')
57 if ($reference === '') {
58 $reference = 'sample';
61 $this->data[$reference] = $data;
66 public function delete(string $reference)
68 if (isset($this->data[$reference])) {
69 unset($this->data[$reference]);
75 public function getOptions()
77 return $this->options;
80 public function saveOptions(array $data)
82 $this->options = $data;
84 // no errors, return empty array
85 return $this->options;
88 public function __toString()
93 public static function getName()
99 * This one is a hack to register this class to the hook
101 public static function registerHook()
103 Hook::register('storage_instance', __DIR__ . '/SampleStorageBackendInstance.php', 'create_instance');