From 3500b1899762f03b583e6fa6103e15006121a83a Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 24 Oct 2016 22:25:34 +0200 Subject: [PATCH] Comments and storage adjustmets --- System/File/FileInterface.php | 45 +++++++++++++++++++++++++++++++-- System/File/Storage.php | 40 ++++++++++++++++++++++++++--- System/File/StorageAbstract.php | 43 +++++++++++++++++++++++++++++-- Uri/Http.php | 1 + 4 files changed, 122 insertions(+), 7 deletions(-) diff --git a/System/File/FileInterface.php b/System/File/FileInterface.php index fc47deb25..3fb42625e 100644 --- a/System/File/FileInterface.php +++ b/System/File/FileInterface.php @@ -31,11 +31,52 @@ namespace phpOMS\System\File; 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 + */ + 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 + */ 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 + */ + 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 + */ public function getContent() : string; } diff --git a/System/File/Storage.php b/System/File/Storage.php index f289bbdd9..bfe61ef05 100644 --- a/System/File/Storage.php +++ b/System/File/Storage.php @@ -30,21 +30,55 @@ namespace phpOMS\System\File; */ final class Storage { + /** + * Registered storage. + * + * @var array + * @since 1.0.0 + */ 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 + */ public static function env(string $env = 'local') : string { 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 { $env = ucfirst(strtolower($env)); $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 + */ + public static function register(string $name, $class) : bool { if (isset(self::$registered[$name])) { return false; diff --git a/System/File/StorageAbstract.php b/System/File/StorageAbstract.php index f3ce96770..f5a8b4274 100644 --- a/System/File/StorageAbstract.php +++ b/System/File/StorageAbstract.php @@ -30,12 +30,40 @@ namespace phpOMS\System\File; */ abstract class StorageAbstract implements DirectoryInterface, FileInterface { + /** + * Singleton instance. + * + * @var StorageAbstract + * @since 1.0.0 + */ 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 + */ + private function __construct() { } + /** + * Get instance. + * + * @return mixed Storage instance. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public static function getInstance() { if(!isset(static::$instance)) { @@ -45,5 +73,16 @@ abstract class StorageAbstract implements DirectoryInterface, FileInterface return static::$instance; } - abstract protected function getType() : ContainerInterface; + /** + * Get storage type. + * + * @return int Storage type. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getType() : int + { + return $this->type; + } } diff --git a/Uri/Http.php b/Uri/Http.php index 7bd77288f..9b2846424 100644 --- a/Uri/Http.php +++ b/Uri/Http.php @@ -14,6 +14,7 @@ * @link http://orange-management.com */ namespace phpOMS\Uri; + use phpOMS\Utils\StringUtils; /**