Browse Source

Add IStorage interface

storage classes should implement this interface
pull/6482/head
fabrixxm 2 years ago
committed by Hypolite Petovan
parent
commit
9b2e3fa916
2 changed files with 46 additions and 10 deletions
  1. +35
    -0
      src/Model/Storage/IStorage.php
  2. +11
    -10
      src/Model/Storage/SystemResource.php

+ 35
- 0
src/Model/Storage/IStorage.php 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);
}

+ 11
- 10
src/Model/Storage/SystemResource.php View File

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

Loading…
Cancel
Save