Add IStorage interface

storage classes should implement this interface
This commit is contained in:
fabrixxm 2018-11-21 09:36:31 +01:00 committed by Hypolite Petovan
parent 3b3c4e8cc7
commit 9b2e3fa916
2 changed files with 46 additions and 10 deletions

View file

@ -0,0 +1,35 @@
<?php
/**
* @file src/Model/Storage/IStorage.php
* @brief Storage backend system
*/
namespace Friendica\Model\Storage;
/**
* @brief Interface for storage backends
*/
interface IStorage
{
/**
* @brief Get data from backend
* @param string $ref Data reference
* @return string
*/
public static function get($ref);
/**
* @brief Put data in backend as $ref. If $ref is null a new reference is created.
* @param string $data Data to save
* @param string $ref Data referece. Optional.
* @return string Saved data referece
*/
public static function put($data, $ref = null);
/**
* @brief Remove data from backend
* @param string $ref Data referece
* @return boolean True on success
*/
public static function delete($ref);
}

View file

@ -1,6 +1,7 @@
<?php <?php
/** /**
* @file src/Model/Storage/SystemStorage.php * @file src/Model/Storage/SystemStorage.php
* @brief Storage backend system
*/ */
namespace Friendica\Model\Storage; namespace Friendica\Model\Storage;
@ -11,19 +12,12 @@ namespace Friendica\Model\Storage;
* This class is used to load system resources, like images. * This class is used to load system resources, like images.
* Is not itended to be selectable by admins as default storage class. * Is not itended to be selectable by admins as default storage class.
*/ */
class SystemResource class SystemResource implements IStorage
{ {
// Valid folders to look for resources // Valid folders to look for resources
const VALID_FOLDERS = [ "images" ]; const VALID_FOLDERS = [ "images" ];
/** public static function get($filename)
* @brief get data
*
* @param string $resourceid
*
* @return string
*/
static function get($filename)
{ {
$folder = dirname($filename); $folder = dirname($filename);
if (!in_array($folder, self::VALID_FOLDERS)) return ""; if (!in_array($folder, self::VALID_FOLDERS)) return "";
@ -31,9 +25,16 @@ class SystemResource
return file_get_contents($filename); return file_get_contents($filename);
} }
static function put($filename, $data)
public static function put($data, $filename=null)
{ {
throw new \BadMethodCallException(); throw new \BadMethodCallException();
} }
public static function delete($filename)
{
throw new \BadMethodCallException();
}
} }