mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-12 06:48:41 +00:00
Comments and storage adjustmets
This commit is contained in:
parent
3631e4918f
commit
3500b18997
|
|
@ -31,11 +31,52 @@ namespace phpOMS\System\File;
|
||||||
interface FileInterface extends ContainerInterface
|
interface FileInterface extends ContainerInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
public static function put(string $path, string $content, bool $overwrite = true) : bool;
|
/**
|
||||||
|
* Save content to file.
|
||||||
|
*
|
||||||
|
* @param string $path File path to save the content to
|
||||||
|
* @param string $content Content to save in file
|
||||||
|
* @param int $mode Mode (overwrite, append)
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public static function put(string $path, string $content, int $mode = 0) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get content from file.
|
||||||
|
*
|
||||||
|
* @param string $path File path of content
|
||||||
|
*
|
||||||
|
* @return string Content of file
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public static function get(string $path) : string;
|
public static function get(string $path) : string;
|
||||||
|
|
||||||
public function putContent() : bool;
|
/**
|
||||||
|
* Save content to file.
|
||||||
|
*
|
||||||
|
* @param string $content Content to save in file
|
||||||
|
* @param int $mode Mode (overwrite, append)
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function putContent(string $content, int $mode = 0) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get content from file.
|
||||||
|
*
|
||||||
|
* @return string Content of file
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function getContent() : string;
|
public function getContent() : string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,21 +30,55 @@ namespace phpOMS\System\File;
|
||||||
*/
|
*/
|
||||||
final class Storage
|
final class Storage
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Registered storage.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private static $registered = [];
|
private static $registered = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get registred env instance.
|
||||||
|
*
|
||||||
|
* @param string $env Environment name
|
||||||
|
*
|
||||||
|
* @throws \Exception Throws exception in case of invalid storage
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public static function env(string $env = 'local') : string
|
public static function env(string $env = 'local') : string
|
||||||
{
|
{
|
||||||
if (isset(self::$registered[$env])) {
|
if (isset(self::$registered[$env])) {
|
||||||
$env = self::$registered[$env];
|
if(is_string(self::$registered[$env])) {
|
||||||
|
$env = self::$registered[$env]::getInstance();
|
||||||
|
} elseif(self::$registered[$env] instanceof StorageAbstract) {
|
||||||
|
$env = self::$registered[$env]::getInstance();
|
||||||
|
} elseif(self::$regsitered[$env] instanceof ContainerInterface) {
|
||||||
|
$env = self::$registered[$env];
|
||||||
|
} else {
|
||||||
|
throw new \Exception('Invalid type');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$env = ucfirst(strtolower($env));
|
$env = ucfirst(strtolower($env));
|
||||||
$env = __NAMESPACE__ . '\\' . $env . '\\' . $env . 'Storage';
|
$env = __NAMESPACE__ . '\\' . $env . '\\' . $env . 'Storage';
|
||||||
|
$env = $env::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $env::getInstance();
|
return $env;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function register(string $name, string $class) : bool
|
/**
|
||||||
|
* Register storage environment.
|
||||||
|
*
|
||||||
|
* @param string $name Name of the environment
|
||||||
|
* @param string|StorageAbstract|mixed $class Class to register. This can be either a namespace path, a anonymous class or storage implementation.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public static function register(string $name, $class) : bool
|
||||||
{
|
{
|
||||||
if (isset(self::$registered[$name])) {
|
if (isset(self::$registered[$name])) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,40 @@ namespace phpOMS\System\File;
|
||||||
*/
|
*/
|
||||||
abstract class StorageAbstract implements DirectoryInterface, FileInterface
|
abstract class StorageAbstract implements DirectoryInterface, FileInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Singleton instance.
|
||||||
|
*
|
||||||
|
* @var StorageAbstract
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
protected static $instance = null;
|
protected static $instance = null;
|
||||||
|
|
||||||
protected function __construct()
|
/**
|
||||||
|
* Storage type.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected $type = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
private function __construct()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get instance.
|
||||||
|
*
|
||||||
|
* @return mixed Storage instance.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public static function getInstance()
|
public static function getInstance()
|
||||||
{
|
{
|
||||||
if(!isset(static::$instance)) {
|
if(!isset(static::$instance)) {
|
||||||
|
|
@ -45,5 +73,16 @@ abstract class StorageAbstract implements DirectoryInterface, FileInterface
|
||||||
return static::$instance;
|
return static::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected function getType() : ContainerInterface;
|
/**
|
||||||
|
* Get storage type.
|
||||||
|
*
|
||||||
|
* @return int Storage type.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function getType() : int
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
* @link http://orange-management.com
|
* @link http://orange-management.com
|
||||||
*/
|
*/
|
||||||
namespace phpOMS\Uri;
|
namespace phpOMS\Uri;
|
||||||
|
|
||||||
use phpOMS\Utils\StringUtils;
|
use phpOMS\Utils\StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user