2018-11-20 17:15:03 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file src/Model/Storage/SystemStorage.php
|
2020-01-19 01:05:23 -05:00
|
|
|
* Storage backend system
|
2018-11-20 17:15:03 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Model\Storage;
|
|
|
|
|
2019-02-18 19:56:41 -05:00
|
|
|
use \BadMethodCallException;
|
|
|
|
|
2018-11-20 17:15:03 -05:00
|
|
|
/**
|
2020-01-19 01:05:23 -05:00
|
|
|
* System resource storage class
|
2018-11-20 17:15:03 -05:00
|
|
|
*
|
|
|
|
* This class is used to load system resources, like images.
|
2018-12-13 23:47:22 -05:00
|
|
|
* Is not intended to be selectable by admins as default storage class.
|
2018-11-20 17:15:03 -05:00
|
|
|
*/
|
2018-11-21 03:36:31 -05:00
|
|
|
class SystemResource implements IStorage
|
2018-11-20 17:15:03 -05:00
|
|
|
{
|
2020-01-06 11:42:28 -05:00
|
|
|
const NAME = 'SystemResource';
|
|
|
|
|
2018-11-20 17:15:03 -05:00
|
|
|
// Valid folders to look for resources
|
2018-11-21 09:10:47 -05:00
|
|
|
const VALID_FOLDERS = ["images"];
|
2018-11-20 17:15:03 -05:00
|
|
|
|
2020-01-06 11:42:28 -05:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function get(string $filename)
|
2018-11-20 17:15:03 -05:00
|
|
|
{
|
|
|
|
$folder = dirname($filename);
|
2018-11-21 09:10:47 -05:00
|
|
|
if (!in_array($folder, self::VALID_FOLDERS)) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
if (!file_exists($filename)) {
|
|
|
|
return "";
|
|
|
|
}
|
2018-11-20 17:15:03 -05:00
|
|
|
return file_get_contents($filename);
|
|
|
|
}
|
|
|
|
|
2020-01-06 11:42:28 -05:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function put(string $data, string $filename = '')
|
2018-11-21 03:36:31 -05:00
|
|
|
{
|
2019-02-18 19:56:41 -05:00
|
|
|
throw new BadMethodCallException();
|
2018-11-21 03:36:31 -05:00
|
|
|
}
|
|
|
|
|
2020-01-06 11:42:28 -05:00
|
|
|
public function delete(string $filename)
|
2018-11-20 17:15:03 -05:00
|
|
|
{
|
2019-02-18 19:56:41 -05:00
|
|
|
throw new BadMethodCallException();
|
2018-11-20 17:15:03 -05:00
|
|
|
}
|
2018-11-21 03:36:31 -05:00
|
|
|
|
2020-01-06 11:42:28 -05:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getOptions()
|
2018-12-13 23:47:22 -05:00
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2020-01-06 11:42:28 -05:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function saveOptions(array $data)
|
2018-12-13 23:47:22 -05:00
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
2018-11-20 17:15:03 -05:00
|
|
|
|
2020-01-06 11:42:28 -05:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return self::NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public static function getName()
|
|
|
|
{
|
|
|
|
return self::NAME;
|
|
|
|
}
|
|
|
|
}
|