From 7898a31c41d03ffdf31a44b867280269e18720f8 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 25 Oct 2016 20:20:38 +0200 Subject: [PATCH] Standardizing Matching static and object calls. Adding some public helper calls. --- System/File/ContainerInterface.php | 8 +- System/File/ContentPutMode.php | 39 +++++ System/File/FileInterface.php | 113 ++++++++++++- System/File/Local/Directory.php | 141 ++++++++-------- System/File/Local/File.php | 259 +++++++++++++++-------------- System/File/Local/FileAbstract.php | 74 ++------- System/File/Local/LocalStorage.php | 180 +++++++++++++++----- System/File/Storage.php | 13 +- 8 files changed, 527 insertions(+), 300 deletions(-) create mode 100644 System/File/ContentPutMode.php diff --git a/System/File/ContainerInterface.php b/System/File/ContainerInterface.php index 3cd63c2a3..a34f009ce 100644 --- a/System/File/ContainerInterface.php +++ b/System/File/ContainerInterface.php @@ -14,7 +14,6 @@ * @link http://orange-management.com */ namespace phpOMS\System\File; -use phpOMS\System\File\Local\FileAbstract; /** * Filesystem class. @@ -72,12 +71,12 @@ interface ContainerInterface * * @param string $path Path of the resource * - * @return int Permissions (e.g. 0644); + * @return string Permissions (e.g. 0644); * * @since 1.0.0 * @author Dennis Eichhorn */ - public static function permission(string $path) : int; + public static function permission(string $path) : string; /** * Get the parent path of the resource. @@ -293,7 +292,6 @@ interface ContainerInterface /** * Move resource to different location. * - * @param string $from Path of the resource to move * @param string $to Path of the resource to move to * @param bool $overwrite Overwrite/replace existing file * @@ -347,7 +345,7 @@ interface ContainerInterface /** * Get the permissions id of the resource. * - * @return int Permissions (e.g. 0644); + * @return string Permissions (e.g. 0644); * * @since 1.0.0 * @author Dennis Eichhorn diff --git a/System/File/ContentPutMode.php b/System/File/ContentPutMode.php new file mode 100644 index 000000000..bac9e88ca --- /dev/null +++ b/System/File/ContentPutMode.php @@ -0,0 +1,39 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\System\File; + +use phpOMS\Datatypes\Enum; + +/** + * Database type enum. + * + * Database types that are supported by the application + * + * @category Framework + * @package phpOMS\System + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +abstract class ContentPutMode extends Enum +{ + const APPEND = 1; + const PREPEND = 2; + const REPLACE = 4; + const CREATE = 8; +} \ No newline at end of file diff --git a/System/File/FileInterface.php b/System/File/FileInterface.php index 3fb42625e..03af5629b 100644 --- a/System/File/FileInterface.php +++ b/System/File/FileInterface.php @@ -43,7 +43,52 @@ interface FileInterface extends ContainerInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function put(string $path, string $content, int $mode = 0) : bool; + public static function put(string $path, string $content, int $mode = ContentPutMode::APPEND | ContentPutMode::CREATE) : bool; + + /** + * Save content to file. + * + * Creates new file if it doesn't exist or overwrites existing file. + * + * @param string $path File path to save the content to + * @param string $content Content to save in file + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function set(string $path, string $content) : bool; + + /** + * Save content to file. + * + * Creates new file if it doesn't exist or appends existing file. + * + * @param string $path File path to save the content to + * @param string $content Content to save in file + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function append(string $path, string $content) : bool; + + /** + * Save content to file. + * + * Creates new file if it doesn't exist or prepends existing file. + * + * @param string $path File path to save the content to + * @param string $content Content to save in file + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function prepend(string $path, string $content) : bool; /** * Get content from file. @@ -57,6 +102,18 @@ interface FileInterface extends ContainerInterface */ public static function get(string $path) : string; + /** + * Get file extension. + * + * @param string $path File path + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function extension(string $path) : string; + /** * Save content to file. * @@ -68,7 +125,49 @@ interface FileInterface extends ContainerInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public function putContent(string $content, int $mode = 0) : bool; + public function putContent(string $content, int $mode = ContentPutMode::APPEND | ContentPutMode::CREATE) : bool; + + /** + * Save content to file. + * + * Creates new file if it doesn't exist or overwrites existing file. + * + * @param string $content Content to save in file + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setContent(string $content) : bool; + + /** + * Save content to file. + * + * Creates new file if it doesn't exist or overwrites existing file. + * + * @param string $content Content to save in file + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function appendContent(string $content) : bool; + + /** + * Save content to file. + * + * Creates new file if it doesn't exist or overwrites existing file. + * + * @param string $content Content to save in file + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function prependContent(string $content) : bool; /** * Get content from file. @@ -79,4 +178,14 @@ interface FileInterface extends ContainerInterface * @author Dennis Eichhorn */ public function getContent() : string; + + /** + * Get file extension. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getExtension() : string; } diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index 7cdad8627..ba1f6d5dc 100644 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -71,12 +71,7 @@ class Directory extends FileAbstract implements DirectoryInterface } /** - * Index directory. - * - * @return void - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public function index() { @@ -183,14 +178,7 @@ class Directory extends FileAbstract implements DirectoryInterface } /** - * Delete directory and all its content. - * - * @param string $path Path to folder - * - * @return bool - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public static function delete(string $path) : bool { @@ -218,14 +206,7 @@ class Directory extends FileAbstract implements DirectoryInterface } /** - * Get parent directory path. - * - * @param string $path Path - * - * @return string - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public static function parent(string $path) : string { @@ -235,55 +216,65 @@ class Directory extends FileAbstract implements DirectoryInterface return implode('/', $path); } + /** + * {@inheritdoc} + */ public static function created(string $path) : \DateTime { // TODO: Implement created() method. } + /** + * {@inheritdoc} + */ public static function changed(string $path) : \DateTime { // TODO: Implement changed() method. } + /** + * {@inheritdoc} + */ public static function owner(string $path) : int { // TODO: Implement owner() method. } + /** + * {@inheritdoc} + */ public static function permission(string $path) : int { // TODO: Implement permission() method. } - /* Iterator */ - + /** + * {@inheritdoc} + */ public static function copy(string $from, string $to, bool $overwrite = false) : bool { // TODO: Implement copy() method. } + /** + * {@inheritdoc} + */ public static function move(string $from, string $to, bool $overwrite = false) : bool { // TODO: Implement move() method. } - public static function put(string $path, string $content, bool $overwrite = true) : bool - { - // TODO: Implement put() method. - } - - public static function get(string $path) : string - { - // TODO: Implement get() method. - } - - /* ArrayAccess */ - - public static function size(string $path) : int + /** + * {@inheritdoc} + */ + public static function size(string $path, bool $recursive = true) : int { // TODO: Implement size() method. } + /** + * {@inheritdoc} + */ public static function exists(string $path) : bool { return file_exists($path); @@ -301,7 +292,7 @@ class Directory extends FileAbstract implements DirectoryInterface */ public function getNode(string $name) : FileAbstract { - return $this->nodes[$name] ?? new NullFile(''); + return $this->nodes[$name] ?? null; } /** @@ -313,16 +304,7 @@ class Directory extends FileAbstract implements DirectoryInterface } /** - * Create directory. - * - * @param string $path Path - * @param string $permission Directory permission - * @param bool $recursive Create parent directories if applicable - * - * @return bool - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public static function create(string $path, string $permission = '0644', bool $recursive = false) : bool { @@ -336,14 +318,7 @@ class Directory extends FileAbstract implements DirectoryInterface } /** - * Remove by name. - * - * @param string $name Name to remove - * - * @return bool - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public function remove(string $name) : bool { @@ -436,38 +411,70 @@ class Directory extends FileAbstract implements DirectoryInterface /** * {@inheritdoc} */ - public function offsetGet($offset) + public static function name(string $path) : string { - return $this->nodes[$offset] ?? null; + // TODO: Implement name() method. } + /** + * {@inheritdoc} + */ + public static function basename(string $path) : string + { + // TODO: Implement basename() method. + } + + /** + * {@inheritdoc} + */ + public static function count(string $path, bool $recursive = false) : int + { + // TODO: Implement count() method. + } + + /** + * {@inheritdoc} + */ public function getParent() : ContainerInterface { // TODO: Implement getParent() method. } - public function copyNode() : bool + /** + * {@inheritdoc} + */ + public function copyNode(string $to, bool $overwrite = false) : bool { // TODO: Implement copyNode() method. } - public function moveNode() : bool + /** + * {@inheritdoc} + */ + public function moveNode(string $to, bool $overwrite = false) : bool { // TODO: Implement moveNode() method. } + /** + * {@inheritdoc} + */ public function deleteNode() : bool { // TODO: Implement deleteNode() method. } - public function putContent() : bool + /** + * Offset to retrieve + * @link http://php.net/manual/en/arrayaccess.offsetget.php + * @param mixed $offset

+ * The offset to retrieve. + *

+ * @return mixed Can return all value types. + * @since 5.0.0 + */ + public function offsetGet($offset) { - // TODO: Implement putContent() method. - } - - public function getContent() : string - { - // TODO: Implement getContent() method. + // TODO: Implement offsetGet() method. } } \ No newline at end of file diff --git a/System/File/Local/File.php b/System/File/Local/File.php index 7c4e59e13..0e1265154 100644 --- a/System/File/Local/File.php +++ b/System/File/Local/File.php @@ -15,6 +15,7 @@ */ namespace phpOMS\System\File\Local; use phpOMS\System\File\ContainerInterface; +use phpOMS\System\File\ContentPutMode; use phpOMS\System\File\FileInterface; use phpOMS\System\File\PathException; @@ -53,12 +54,7 @@ class File extends FileAbstract implements FileInterface } /** - * Index file. - * - * @return void - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public function index() { @@ -68,27 +64,17 @@ class File extends FileAbstract implements FileInterface } /** - * Save string to file. - * - * If the directory doesn't exist where the string should be saved it will be created - * as well as potential subdirectories. The directories will be created with '0644' - * permission. - * - * @param string $path Path to save the string to - * @param string $content Content to save to file - * @param bool $overwrite Should the file be overwritten if it already exists - * - * @example File::put('/var/www/html/test.txt', 'string'); // true - * @example File::put('/var/www/html/test.txt', 'string', false); // false - * - * @return bool Returns true on successfule file write and false on failure - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ - public static function put(string $path, string $content, bool $overwrite = true) : bool + public static function put(string $path, string $content, int $mode = ContentPutMode::APPEND | ContentPutMode::CREATE) : bool { - if ($overwrite || !file_exists($path)) { + // todo: create all else cases, right now all getting handled the same way which is wrong + if ( + (($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && file_exists($path)) + || (($mode & ContentPutMode::PREPEND) === ContentPutMode::PREPEND && file_exists($path)) + || (($mode & ContentPutMode::REPLACE) === ContentPutMode::REPLACE && file_exists($path)) + || (!file_exists($path) && ($mode & ContentPutMode::CREATE) === ContentPutMode::CREATE) + ) { if (!Directory::exists(dirname($path))) { Directory::create(dirname($path), '0644', true); } @@ -102,18 +88,7 @@ class File extends FileAbstract implements FileInterface } /** - * Get content of file. - * - * @param string $path Path to read from - * - * @example File::get('/var/www/html/test.txt'); - * - * @return string The content of the file to read from. - * - * @throws PathException In case the file doesn't exist this exception gets thrown. - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public static function get(string $path) : string { @@ -125,16 +100,31 @@ class File extends FileAbstract implements FileInterface } /** - * Checks if a file exists. - * - * @param string $path Path of the file to check the existance for. - * - * @example File::exists('/var/www/html/test.txt'); - * - * @return bool Returns true if the file exists and false if it doesn't. - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} + */ + public static function set(string $path, string $content) : bool + { + return self::put($path, $content, ContentPutMode::REPLACE | ContentPutMode::CREATE); + } + + /** + * {@inheritdoc} + */ + public static function append(string $path, string $content) : bool + { + return self::put($path, $content, ContentPutMode::APPEND | ContentPutMode::CREATE); + } + + /** + * {@inheritdoc} + */ + public static function prepend(string $path, string $content) : bool + { + return self::put($path, $content, ContentPutMode::PREPEND | ContentPutMode::CREATE); + } + + /** + * {@inheritdoc} */ public static function exists(string $path) : bool { @@ -142,16 +132,7 @@ class File extends FileAbstract implements FileInterface } /** - * Gets the parent directory path of the specified file. - * - * @param string $path Path of the file to get the parent directory for. - * - * @example File::parent('/var/www/html/test.txt'); // /var/www - * - * @return string Returns the parent full directory path. - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public static function parent(string $path) : string { @@ -159,18 +140,7 @@ class File extends FileAbstract implements FileInterface } /** - * Gets the date when the file got created. - * - * @param string $path Path of the file to get the date of creation for. - * - * @return \DateTime Returns the \DateTime of when the file was created. - * - * @throws PathException Throws this exception if the file to get the creation date for doesn't exist. - * - * @example File::created('/var/www/html/test.txt'); - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public static function created(string $path) : \DateTime { @@ -185,18 +155,7 @@ class File extends FileAbstract implements FileInterface } /** - * Gets the date when the file got changed the last time. - * - * @param string $path Path of the file to get the last date of change for. - * - * @return \DateTime Returns the \DateTime of when the file was last changed. - * - * @throws PathException Throws this exception if the file to get the last change date for doesn't exist. - * - * @example File::changed('/var/www/html/test.txt'); - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public static function changed(string $path) : \DateTime { @@ -211,16 +170,9 @@ class File extends FileAbstract implements FileInterface } /** - * Gets the size of a file in bytes. - * - * @param string $path Path of the file to get the size for. - * - * @return int Returns the size of the file. - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ - public static function size(string $path) : int + public static function size(string $path, bool $recursive = true) : int { if (!file_exists($path)) { throw new PathException($path); @@ -230,14 +182,7 @@ class File extends FileAbstract implements FileInterface } /** - * Gets the id of the owner of the file. - * - * @param string $path Path of the file to get the owner for. - * - * @return int Returns the owner of the file. - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public static function owner(string $path) : int { @@ -249,14 +194,7 @@ class File extends FileAbstract implements FileInterface } /** - * Gets the permission of a file. - * - * @param string $path Path of the file to get the permission for. - * - * @return int Returns the permission of the file. - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public static function permission(string $path) : int { @@ -282,6 +220,9 @@ class File extends FileAbstract implements FileInterface return dirname($path); } + /** + * {@inheritdoc} + */ public static function copy(string $from, string $to, bool $overwrite = false) : bool { if (!file_exists($from)) { @@ -301,6 +242,9 @@ class File extends FileAbstract implements FileInterface return false; } + /** + * {@inheritdoc} + */ public static function move(string $from, string $to, bool $overwrite = false) : bool { if (!file_exists($from)) { @@ -320,6 +264,9 @@ class File extends FileAbstract implements FileInterface return false; } + /** + * {@inheritdoc} + */ public static function delete(string $path) : bool { if (!file_exists($path)) { @@ -349,6 +296,9 @@ class File extends FileAbstract implements FileInterface return self::create($this->path); } + /** + * {@inheritdoc} + */ public static function create(string $path) : bool { if (!file_exists($path)) { @@ -365,12 +315,7 @@ class File extends FileAbstract implements FileInterface } /** - * Gets the content of the current file. - * - * @return string Content of the file. - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public function getContent() : string { @@ -378,23 +323,40 @@ class File extends FileAbstract implements FileInterface } /** - * Set file content. - * - * @param string $content Content to set - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ - public function setContent(string $content) + public function setContent(string $content) : bool { - file_put_contents($this->path, $content); + return $this->putContent($content, ContentPutMode::REPLACE | ContentPutMode::CREATE); } - public function getFileName() : string + /** + * {@inheritdoc} + */ + public function appendContent(string $content) : bool + { + return $this->putContent($content, ContentPutMode::APPEND | ContentPutMode::CREATE); + } + + /** + * {@inheritdoc} + */ + public function prependContent(string $content) : bool + { + return $this->putContent($content, ContentPutMode::PREPEND | ContentPutMode::CREATE); + } + + /** + * {@inheritdoc} + */ + public function getName() : string { return explode('.', $this->name)[0]; } + /** + * {@inheritdoc} + */ public function getExtension() : string { $extension = explode('.', $this->name); @@ -402,28 +364,77 @@ class File extends FileAbstract implements FileInterface return $extension[1] ?? ''; } + /** + * {@inheritdoc} + */ public function getParent() : ContainerInterface { // TODO: Implement getParent() method. } - public function copyNode() : bool + /** + * {@inheritdoc} + */ + public function copyNode(string $to, bool $overwrite = false) : bool { // TODO: Implement copyNode() method. } - public function moveNode() : bool + /** + * {@inheritdoc} + */ + public function moveNode(string $to, bool $overwrite = false) : bool { // TODO: Implement moveNode() method. } + /** + * {@inheritdoc} + */ public function deleteNode() : bool { // TODO: Implement deleteNode() method. } - public function putContent() : bool + /** + * {@inheritdoc} + */ + public function putContent(string $content, int $mode = ContentPutMode::APPEND | ContentPutMode::CREATE) : bool { // TODO: Implement putContent() method. } + + /** + * {@inheritdoc} + */ + public static function name(string $path) : string + { + return explode('.', basename($path))[0]; + } + + /** + * {@inheritdoc} + */ + public static function basename(string $path) : string + { + // TODO: Implement basename() method. + } + + /** + * {@inheritdoc} + */ + public static function count(string $path, bool $recursive = false) : int + { + // TODO: Implement count() method. + } + + /** + * {@inheritdoc} + */ + public static function extension(string $path) : string + { + $extension = explode('.', basename($path)); + + return $extension[1] ?? ''; + } } \ No newline at end of file diff --git a/System/File/Local/FileAbstract.php b/System/File/Local/FileAbstract.php index 1360fbc57..7fdcf2f7a 100644 --- a/System/File/Local/FileAbstract.php +++ b/System/File/Local/FileAbstract.php @@ -113,38 +113,23 @@ abstract class FileAbstract implements ContainerInterface } /** - * Get directory/file count. - * - * @return int - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ - public function getCount() : int + public function getCount(bool $recursive = true) : int { return $this->count; } /** - * Get directory/file size. - * - * @return int - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ - public function getSize() : int + public function getSize(bool $recursive = true) : int { return $this->size; } /** - * Get name. - * - * @return string - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public function getName() : string { @@ -152,12 +137,7 @@ abstract class FileAbstract implements ContainerInterface } /** - * Get path. - * - * @return string - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public function getPath() : string { @@ -165,12 +145,7 @@ abstract class FileAbstract implements ContainerInterface } /** - * Get parent directory. - * - * @return Directory - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public function parentNode() : Directory { @@ -178,12 +153,7 @@ abstract class FileAbstract implements ContainerInterface } /** - * Get created at. - * - * @return \DateTime - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public function getCreatedAt() : \DateTime { @@ -191,12 +161,7 @@ abstract class FileAbstract implements ContainerInterface } /** - * Get last changed at. - * - * @return \DateTime - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public function getChangedAt() : \DateTime { @@ -204,12 +169,7 @@ abstract class FileAbstract implements ContainerInterface } /** - * Get owner. - * - * @return int - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public function getOwner() : int { @@ -217,12 +177,7 @@ abstract class FileAbstract implements ContainerInterface } /** - * Get permission. - * - * @return string - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public function getPermission() : string { @@ -230,12 +185,7 @@ abstract class FileAbstract implements ContainerInterface } /** - * (Re-)Index path. - * - * @return void - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public function index() { diff --git a/System/File/Local/LocalStorage.php b/System/File/Local/LocalStorage.php index 8c4d0ccce..4c964fb88 100644 --- a/System/File/Local/LocalStorage.php +++ b/System/File/Local/LocalStorage.php @@ -15,7 +15,6 @@ */ namespace phpOMS\System\File\Local; use phpOMS\System\File\ContainerInterface; -use phpOMS\System\File\FileInterface; use phpOMS\System\File\StorageAbstract; /** @@ -33,127 +32,225 @@ use phpOMS\System\File\StorageAbstract; */ class LocalStorage extends StorageAbstract { - + /** + * {@inheritdoc} + */ public static function created(string $path) : \DateTime { // TODO: Implement created() method. } + /** + * {@inheritdoc} + */ public static function changed(string $path) : \DateTime { // TODO: Implement changed() method. } + /** + * {@inheritdoc} + */ public static function owner(string $path) : int { // TODO: Implement owner() method. } - public static function permission(string $path) : int + /** + * {@inheritdoc} + */ + public static function permission(string $path) : string { // TODO: Implement permission() method. } + /** + * {@inheritdoc} + */ public static function parent(string $path) : string { // TODO: Implement parent() method. } + /** + * {@inheritdoc} + */ public static function create(string $path) : bool { // TODO: Implement create() method. } + /** + * {@inheritdoc} + */ public static function delete(string $path) : bool { // TODO: Implement delete() method. } + /** + * {@inheritdoc} + */ public static function copy(string $from, string $to, bool $overwrite = false) : bool { // TODO: Implement copy() method. } + /** + * {@inheritdoc} + */ public static function move(string $from, string $to, bool $overwrite = false) : bool { // TODO: Implement move() method. } - public static function size(string $path) : int + /** + * {@inheritdoc} + */ + public static function size(string $path, bool $recursive = true) : int { // TODO: Implement size() method. } + /** + * {@inheritdoc} + */ public static function exists(string $path) : bool { // TODO: Implement exists() method. } - public function getCount() : int + /** + * {@inheritdoc} + */ + public static function name(string $path) : string + { + // TODO: Implement name() method. + } + + /** + * {@inheritdoc} + */ + public static function basename(string $path) : string + { + // TODO: Implement basename() method. + } + + /** + * {@inheritdoc} + */ + public static function count(string $path, bool $recursive = false) : int + { + // TODO: Implement count() method. + } + + /** + * {@inheritdoc} + */ + public function getCount(bool $recursive = false) : int { // TODO: Implement getCount() method. } - public function getSize() : int + /** + * {@inheritdoc} + */ + public function getSize(bool $recursive = false) : int { // TODO: Implement getSize() method. } + /** + * {@inheritdoc} + */ public function getName() : string { // TODO: Implement getName() method. } + /** + * {@inheritdoc} + */ public function getPath() : string { // TODO: Implement getPath() method. } + /** + * {@inheritdoc} + */ public function getParent() : ContainerInterface { // TODO: Implement getParent() method. } + /** + * {@inheritdoc} + */ public function createNode() : bool { // TODO: Implement createNode() method. } - public function copyNode() : bool + /** + * {@inheritdoc} + */ + public function copyNode(string $to, bool $overwrite = false) : bool { // TODO: Implement copyNode() method. } - public function moveNode() : bool + /** + * {@inheritdoc} + */ + public function moveNode(string $to, bool $overwrite = false) : bool { // TODO: Implement moveNode() method. } + /** + * {@inheritdoc} + */ public function deleteNode() : bool { // TODO: Implement deleteNode() method. } + /** + * {@inheritdoc} + */ public function getCreatedAt() : \DateTime { // TODO: Implement getCreatedAt() method. } + /** + * {@inheritdoc} + */ public function getChangedAt() : \DateTime { // TODO: Implement getChangedAt() method. } + /** + * {@inheritdoc} + */ public function getOwner() : int { // TODO: Implement getOwner() method. } + /** + * {@inheritdoc} + */ public function getPermission() : string { // TODO: Implement getPermission() method. } + /** + * {@inheritdoc} + */ public function index() { // TODO: Implement index() method. @@ -161,7 +258,7 @@ class LocalStorage extends StorageAbstract /** * Return the current element - * @link http://php.net/manual/en/iterator.current.php + * @link http://php.net/manual/en/iterator.current.php * @return mixed Can return any type. * @since 5.0.0 */ @@ -172,7 +269,7 @@ class LocalStorage extends StorageAbstract /** * Move forward to next element - * @link http://php.net/manual/en/iterator.next.php + * @link http://php.net/manual/en/iterator.next.php * @return void Any returned value is ignored. * @since 5.0.0 */ @@ -183,7 +280,7 @@ class LocalStorage extends StorageAbstract /** * Return the key of the current element - * @link http://php.net/manual/en/iterator.key.php + * @link http://php.net/manual/en/iterator.key.php * @return mixed scalar on success, or null on failure. * @since 5.0.0 */ @@ -194,7 +291,7 @@ class LocalStorage extends StorageAbstract /** * Checks if current position is valid - * @link http://php.net/manual/en/iterator.valid.php + * @link http://php.net/manual/en/iterator.valid.php * @return boolean The return value will be casted to boolean and then evaluated. * Returns true on success or false on failure. * @since 5.0.0 @@ -206,7 +303,7 @@ class LocalStorage extends StorageAbstract /** * Rewind the Iterator to the first element - * @link http://php.net/manual/en/iterator.rewind.php + * @link http://php.net/manual/en/iterator.rewind.php * @return void Any returned value is ignored. * @since 5.0.0 */ @@ -217,14 +314,14 @@ class LocalStorage extends StorageAbstract /** * Whether a offset exists - * @link http://php.net/manual/en/arrayaccess.offsetexists.php + * @link http://php.net/manual/en/arrayaccess.offsetexists.php * @param mixed $offset

- * An offset to check for. - *

+ * An offset to check for. + *

* @return boolean true on success or false on failure. - *

- *

- * The return value will be casted to boolean if non-boolean was returned. + *

+ *

+ * The return value will be casted to boolean if non-boolean was returned. * @since 5.0.0 */ public function offsetExists($offset) @@ -234,10 +331,10 @@ class LocalStorage extends StorageAbstract /** * Offset to retrieve - * @link http://php.net/manual/en/arrayaccess.offsetget.php + * @link http://php.net/manual/en/arrayaccess.offsetget.php * @param mixed $offset

- * The offset to retrieve. - *

+ * The offset to retrieve. + *

* @return mixed Can return all value types. * @since 5.0.0 */ @@ -248,13 +345,13 @@ class LocalStorage extends StorageAbstract /** * Offset to set - * @link http://php.net/manual/en/arrayaccess.offsetset.php + * @link http://php.net/manual/en/arrayaccess.offsetset.php * @param mixed $offset

- * The offset to assign the value to. - *

- * @param mixed $value

- * The value to set. - *

+ * The offset to assign the value to. + *

+ * @param mixed $value

+ * The value to set. + *

* @return void * @since 5.0.0 */ @@ -265,10 +362,10 @@ class LocalStorage extends StorageAbstract /** * Offset to unset - * @link http://php.net/manual/en/arrayaccess.offsetunset.php + * @link http://php.net/manual/en/arrayaccess.offsetunset.php * @param mixed $offset

- * The offset to unset. - *

+ * The offset to unset. + *

* @return void * @since 5.0.0 */ @@ -277,28 +374,35 @@ class LocalStorage extends StorageAbstract // TODO: Implement offsetUnset() method. } - public static function put(string $path, string $content, bool $overwrite = true) : bool + /** + * {@inheritdoc} + */ + public static function put(string $path, string $content, int $mode = 0) : bool { // TODO: Implement put() method. } + /** + * {@inheritdoc} + */ public static function get(string $path) : string { // TODO: Implement get() method. } - public function putContent() : bool + /** + * {@inheritdoc} + */ + public function putContent(string $content, int $mode = 0) : bool { // TODO: Implement putContent() method. } + /** + * {@inheritdoc} + */ public function getContent() : string { // TODO: Implement getContent() method. } - - protected function getType() : ContainerInterface - { - // TODO: Implement getType() method. - } } \ No newline at end of file diff --git a/System/File/Storage.php b/System/File/Storage.php index bfe61ef05..0df22ac37 100644 --- a/System/File/Storage.php +++ b/System/File/Storage.php @@ -37,25 +37,32 @@ final class Storage * @since 1.0.0 */ private static $registered = []; + + private function __construct() + { + + } /** * Get registred env instance. * * @param string $env Environment name * + * @return StorageAbstract + * * @throws \Exception Throws exception in case of invalid storage * * @since 1.0.0 * @author Dennis Eichhorn */ - public static function env(string $env = 'local') : string + public static function env(string $env = 'local') : StorageAbstract { if (isset(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) { + } elseif(self::$registered[$env] instanceof ContainerInterface) { $env = self::$registered[$env]; } else { throw new \Exception('Invalid type'); @@ -75,6 +82,8 @@ final class Storage * @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. * + * @return bool + * * @since 1.0.0 * @author Dennis Eichhorn */