2018-11-20 22:15:03 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2021-03-29 06:40:20 +00:00
|
|
|
* @copyright Copyright (C) 2010-2021, the Friendica project
|
2020-02-09 14:45:36 +00:00
|
|
|
*
|
|
|
|
* @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/>.
|
|
|
|
*
|
2018-11-20 22:15:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Model\Storage;
|
|
|
|
|
|
|
|
/**
|
2020-01-19 06:05:23 +00:00
|
|
|
* System resource storage class
|
2018-11-20 22:15:03 +00:00
|
|
|
*
|
|
|
|
* This class is used to load system resources, like images.
|
2018-12-14 04:47:22 +00:00
|
|
|
* Is not intended to be selectable by admins as default storage class.
|
2018-11-20 22:15:03 +00:00
|
|
|
*/
|
2018-11-21 08:36:31 +00:00
|
|
|
class SystemResource implements IStorage
|
2018-11-20 22:15:03 +00:00
|
|
|
{
|
2020-01-06 16:42:28 +00:00
|
|
|
const NAME = 'SystemResource';
|
|
|
|
|
2018-11-20 22:15:03 +00:00
|
|
|
// Valid folders to look for resources
|
2018-11-21 14:10:47 +00:00
|
|
|
const VALID_FOLDERS = ["images"];
|
2018-11-20 22:15:03 +00:00
|
|
|
|
2020-01-06 16:42:28 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2021-08-01 11:06:19 +00:00
|
|
|
public function get(string $reference): string
|
2018-11-20 22:15:03 +00:00
|
|
|
{
|
2021-08-01 11:06:19 +00:00
|
|
|
$folder = dirname($reference);
|
2018-11-21 14:10:47 +00:00
|
|
|
if (!in_array($folder, self::VALID_FOLDERS)) {
|
2021-08-01 11:06:19 +00:00
|
|
|
throw new ReferenceStorageException(sprintf('System Resource is invalid for reference %s, no valid folder found', $reference));
|
2018-11-21 14:10:47 +00:00
|
|
|
}
|
2021-08-01 11:06:19 +00:00
|
|
|
if (!file_exists($reference)) {
|
|
|
|
throw new StorageException(sprintf('System Resource is invalid for reference %s, the file doesn\'t exist', $reference));
|
2018-11-21 14:10:47 +00:00
|
|
|
}
|
2021-08-01 11:06:19 +00:00
|
|
|
$content = file_get_contents($reference);
|
2018-11-21 08:36:31 +00:00
|
|
|
|
2021-08-01 11:06:19 +00:00
|
|
|
if ($content === false) {
|
|
|
|
throw new StorageException(sprintf('Cannot get content for reference %s', $reference));
|
|
|
|
}
|
2018-12-14 04:47:22 +00:00
|
|
|
|
2021-08-01 11:06:19 +00:00
|
|
|
return $content;
|
2018-12-14 04:47:22 +00:00
|
|
|
}
|
2018-11-20 22:15:03 +00:00
|
|
|
|
2020-01-06 16:42:28 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return self::NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2021-08-01 11:06:19 +00:00
|
|
|
public static function getName(): string
|
2020-01-06 16:42:28 +00:00
|
|
|
{
|
|
|
|
return self::NAME;
|
|
|
|
}
|
|
|
|
}
|