]> git.mxchange.org Git - friendica.git/blobdiff - tests/Util/SampleStorageBackend.php
Merge pull request #13651 from annando/picture-upload
[friendica.git] / tests / Util / SampleStorageBackend.php
index 3f4eb90ada0f91cbddc18426813ad9f4dd75b448..ac9a21b66295fafcb8c3b3c173787709ceafc579 100644 (file)
@@ -1,15 +1,35 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Test\Util;
 
-use Friendica\Model\Storage\IStorage;
+use Friendica\Core\Hook;
+use Friendica\Core\Storage\Capability\ICanWriteToStorage;
 
-use Friendica\Core\L10n\L10n;
+use Friendica\Core\L10n;
 
 /**
  * A backend storage example class
  */
-class SampleStorageBackend implements IStorage
+class SampleStorageBackend implements ICanWriteToStorage
 {
        const NAME = 'Sample Storage';
 
@@ -42,14 +62,14 @@ class SampleStorageBackend implements IStorage
                $this->l10n = $l10n;
        }
 
-       public function get(string $reference)
+       public function get(string $reference): string
        {
                // we return always the same image data. Which file we load is defined by
                // a config key
-               return $this->data[$reference] ?? null;
+               return $this->data[$reference] ?? '';
        }
 
-       public function put(string $data, string $reference = '')
+       public function put(string $data, string $reference = ''): string
        {
                if ($reference === '') {
                        $reference = 'sample';
@@ -69,12 +89,12 @@ class SampleStorageBackend implements IStorage
                return true;
        }
 
-       public function getOptions()
+       public function getOptions(): array
        {
                return $this->options;
        }
 
-       public function saveOptions(array $data)
+       public function saveOptions(array $data): array
        {
                $this->options = $data;
 
@@ -82,13 +102,21 @@ class SampleStorageBackend implements IStorage
                return $this->options;
        }
 
-       public function __toString()
+       public function __toString(): string
        {
                return self::NAME;
        }
 
-       public static function getName()
+       public static function getName(): string
        {
                return self::NAME;
        }
+
+       /**
+        * This one is a hack to register this class to the hook
+        */
+       public static function registerHook()
+       {
+               Hook::register('storage_instance', __DIR__ . '/SampleStorageBackendInstance.php', 'create_instance');
+       }
 }