Standardizing

Matching static and object calls.
Adding some public helper calls.
This commit is contained in:
Dennis Eichhorn 2016-10-25 20:20:38 +02:00
parent a225921e75
commit 7898a31c41
8 changed files with 527 additions and 300 deletions

View File

@ -14,7 +14,6 @@
* @link http://orange-management.com * @link http://orange-management.com
*/ */
namespace phpOMS\System\File; namespace phpOMS\System\File;
use phpOMS\System\File\Local\FileAbstract;
/** /**
* Filesystem class. * Filesystem class.
@ -72,12 +71,12 @@ interface ContainerInterface
* *
* @param string $path Path of the resource * @param string $path Path of the resource
* *
* @return int Permissions (e.g. 0644); * @return string Permissions (e.g. 0644);
* *
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public static function permission(string $path) : int; public static function permission(string $path) : string;
/** /**
* Get the parent path of the resource. * Get the parent path of the resource.
@ -293,7 +292,6 @@ interface ContainerInterface
/** /**
* Move resource to different location. * 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 string $to Path of the resource to move to
* @param bool $overwrite Overwrite/replace existing file * @param bool $overwrite Overwrite/replace existing file
* *
@ -347,7 +345,7 @@ interface ContainerInterface
/** /**
* Get the permissions id of the resource. * Get the permissions id of the resource.
* *
* @return int Permissions (e.g. 0644); * @return string Permissions (e.g. 0644);
* *
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>

View File

@ -0,0 +1,39 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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;
}

View File

@ -43,7 +43,52 @@ interface FileInterface extends ContainerInterface
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
public static function prepend(string $path, string $content) : bool;
/** /**
* Get content from file. * Get content from file.
@ -57,6 +102,18 @@ interface FileInterface extends ContainerInterface
*/ */
public static function get(string $path) : string; public static function get(string $path) : string;
/**
* Get file extension.
*
* @param string $path File path
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function extension(string $path) : string;
/** /**
* Save content to file. * Save content to file.
* *
@ -68,7 +125,49 @@ interface FileInterface extends ContainerInterface
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
public function prependContent(string $content) : bool;
/** /**
* Get content from file. * Get content from file.
@ -79,4 +178,14 @@ interface FileInterface extends ContainerInterface
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function getContent() : string; public function getContent() : string;
/**
* Get file extension.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getExtension() : string;
} }

View File

@ -71,12 +71,7 @@ class Directory extends FileAbstract implements DirectoryInterface
} }
/** /**
* Index directory. * {@inheritdoc}
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function index() public function index()
{ {
@ -183,14 +178,7 @@ class Directory extends FileAbstract implements DirectoryInterface
} }
/** /**
* Delete directory and all its content. * {@inheritdoc}
*
* @param string $path Path to folder
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public static function delete(string $path) : bool public static function delete(string $path) : bool
{ {
@ -218,14 +206,7 @@ class Directory extends FileAbstract implements DirectoryInterface
} }
/** /**
* Get parent directory path. * {@inheritdoc}
*
* @param string $path Path
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public static function parent(string $path) : string public static function parent(string $path) : string
{ {
@ -235,55 +216,65 @@ class Directory extends FileAbstract implements DirectoryInterface
return implode('/', $path); return implode('/', $path);
} }
/**
* {@inheritdoc}
*/
public static function created(string $path) : \DateTime public static function created(string $path) : \DateTime
{ {
// TODO: Implement created() method. // TODO: Implement created() method.
} }
/**
* {@inheritdoc}
*/
public static function changed(string $path) : \DateTime public static function changed(string $path) : \DateTime
{ {
// TODO: Implement changed() method. // TODO: Implement changed() method.
} }
/**
* {@inheritdoc}
*/
public static function owner(string $path) : int public static function owner(string $path) : int
{ {
// TODO: Implement owner() method. // TODO: Implement owner() method.
} }
/**
* {@inheritdoc}
*/
public static function permission(string $path) : int public static function permission(string $path) : int
{ {
// TODO: Implement permission() method. // TODO: Implement permission() method.
} }
/* Iterator */ /**
* {@inheritdoc}
*/
public static function copy(string $from, string $to, bool $overwrite = false) : bool public static function copy(string $from, string $to, bool $overwrite = false) : bool
{ {
// TODO: Implement copy() method. // TODO: Implement copy() method.
} }
/**
* {@inheritdoc}
*/
public static function move(string $from, string $to, bool $overwrite = false) : bool public static function move(string $from, string $to, bool $overwrite = false) : bool
{ {
// TODO: Implement move() method. // TODO: Implement move() method.
} }
public static function put(string $path, string $content, bool $overwrite = true) : bool /**
{ * {@inheritdoc}
// TODO: Implement put() method. */
} public static function size(string $path, bool $recursive = true) : int
public static function get(string $path) : string
{
// TODO: Implement get() method.
}
/* ArrayAccess */
public static function size(string $path) : int
{ {
// TODO: Implement size() method. // TODO: Implement size() method.
} }
/**
* {@inheritdoc}
*/
public static function exists(string $path) : bool public static function exists(string $path) : bool
{ {
return file_exists($path); return file_exists($path);
@ -301,7 +292,7 @@ class Directory extends FileAbstract implements DirectoryInterface
*/ */
public function getNode(string $name) : FileAbstract 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. * {@inheritdoc}
*
* @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 <d.eichhorn@oms.com>
*/ */
public static function create(string $path, string $permission = '0644', bool $recursive = false) : bool 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. * {@inheritdoc}
*
* @param string $name Name to remove
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function remove(string $name) : bool public function remove(string $name) : bool
{ {
@ -436,38 +411,70 @@ class Directory extends FileAbstract implements DirectoryInterface
/** /**
* {@inheritdoc} * {@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 public function getParent() : ContainerInterface
{ {
// TODO: Implement getParent() method. // TODO: Implement getParent() method.
} }
public function copyNode() : bool /**
* {@inheritdoc}
*/
public function copyNode(string $to, bool $overwrite = false) : bool
{ {
// TODO: Implement copyNode() method. // TODO: Implement copyNode() method.
} }
public function moveNode() : bool /**
* {@inheritdoc}
*/
public function moveNode(string $to, bool $overwrite = false) : bool
{ {
// TODO: Implement moveNode() method. // TODO: Implement moveNode() method.
} }
/**
* {@inheritdoc}
*/
public function deleteNode() : bool public function deleteNode() : bool
{ {
// TODO: Implement deleteNode() method. // TODO: Implement deleteNode() method.
} }
public function putContent() : bool /**
* Offset to retrieve
* @link http://php.net/manual/en/arrayaccess.offsetget.php
* @param mixed $offset <p>
* The offset to retrieve.
* </p>
* @return mixed Can return all value types.
* @since 5.0.0
*/
public function offsetGet($offset)
{ {
// TODO: Implement putContent() method. // TODO: Implement offsetGet() method.
}
public function getContent() : string
{
// TODO: Implement getContent() method.
} }
} }

View File

@ -15,6 +15,7 @@
*/ */
namespace phpOMS\System\File\Local; namespace phpOMS\System\File\Local;
use phpOMS\System\File\ContainerInterface; use phpOMS\System\File\ContainerInterface;
use phpOMS\System\File\ContentPutMode;
use phpOMS\System\File\FileInterface; use phpOMS\System\File\FileInterface;
use phpOMS\System\File\PathException; use phpOMS\System\File\PathException;
@ -53,12 +54,7 @@ class File extends FileAbstract implements FileInterface
} }
/** /**
* Index file. * {@inheritdoc}
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function index() public function index()
{ {
@ -68,27 +64,17 @@ class File extends FileAbstract implements FileInterface
} }
/** /**
* Save string to file. * {@inheritdoc}
*
* 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 <d.eichhorn@oms.com>
*/ */
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))) { if (!Directory::exists(dirname($path))) {
Directory::create(dirname($path), '0644', true); Directory::create(dirname($path), '0644', true);
} }
@ -102,18 +88,7 @@ class File extends FileAbstract implements FileInterface
} }
/** /**
* Get content of file. * {@inheritdoc}
*
* @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 <d.eichhorn@oms.com>
*/ */
public static function get(string $path) : string public static function get(string $path) : string
{ {
@ -125,16 +100,31 @@ class File extends FileAbstract implements FileInterface
} }
/** /**
* Checks if a file exists. * {@inheritdoc}
* */
* @param string $path Path of the file to check the existance for. public static function set(string $path, string $content) : bool
* {
* @example File::exists('/var/www/html/test.txt'); return self::put($path, $content, ContentPutMode::REPLACE | ContentPutMode::CREATE);
* }
* @return bool Returns true if the file exists and false if it doesn't.
* /**
* @since 1.0.0 * {@inheritdoc}
* @author Dennis Eichhorn <d.eichhorn@oms.com> */
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 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. * {@inheritdoc}
*
* @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 <d.eichhorn@oms.com>
*/ */
public static function parent(string $path) : string 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. * {@inheritdoc}
*
* @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 <d.eichhorn@oms.com>
*/ */
public static function created(string $path) : \DateTime 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. * {@inheritdoc}
*
* @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 <d.eichhorn@oms.com>
*/ */
public static function changed(string $path) : \DateTime 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. * {@inheritdoc}
*
* @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 <d.eichhorn@oms.com>
*/ */
public static function size(string $path) : int public static function size(string $path, bool $recursive = true) : int
{ {
if (!file_exists($path)) { if (!file_exists($path)) {
throw new PathException($path); throw new PathException($path);
@ -230,14 +182,7 @@ class File extends FileAbstract implements FileInterface
} }
/** /**
* Gets the id of the owner of the file. * {@inheritdoc}
*
* @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 <d.eichhorn@oms.com>
*/ */
public static function owner(string $path) : int public static function owner(string $path) : int
{ {
@ -249,14 +194,7 @@ class File extends FileAbstract implements FileInterface
} }
/** /**
* Gets the permission of a file. * {@inheritdoc}
*
* @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 <d.eichhorn@oms.com>
*/ */
public static function permission(string $path) : int public static function permission(string $path) : int
{ {
@ -282,6 +220,9 @@ class File extends FileAbstract implements FileInterface
return dirname($path); return dirname($path);
} }
/**
* {@inheritdoc}
*/
public static function copy(string $from, string $to, bool $overwrite = false) : bool public static function copy(string $from, string $to, bool $overwrite = false) : bool
{ {
if (!file_exists($from)) { if (!file_exists($from)) {
@ -301,6 +242,9 @@ class File extends FileAbstract implements FileInterface
return false; return false;
} }
/**
* {@inheritdoc}
*/
public static function move(string $from, string $to, bool $overwrite = false) : bool public static function move(string $from, string $to, bool $overwrite = false) : bool
{ {
if (!file_exists($from)) { if (!file_exists($from)) {
@ -320,6 +264,9 @@ class File extends FileAbstract implements FileInterface
return false; return false;
} }
/**
* {@inheritdoc}
*/
public static function delete(string $path) : bool public static function delete(string $path) : bool
{ {
if (!file_exists($path)) { if (!file_exists($path)) {
@ -349,6 +296,9 @@ class File extends FileAbstract implements FileInterface
return self::create($this->path); return self::create($this->path);
} }
/**
* {@inheritdoc}
*/
public static function create(string $path) : bool public static function create(string $path) : bool
{ {
if (!file_exists($path)) { if (!file_exists($path)) {
@ -365,12 +315,7 @@ class File extends FileAbstract implements FileInterface
} }
/** /**
* Gets the content of the current file. * {@inheritdoc}
*
* @return string Content of the file.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function getContent() : string public function getContent() : string
{ {
@ -378,23 +323,40 @@ class File extends FileAbstract implements FileInterface
} }
/** /**
* Set file content. * {@inheritdoc}
*
* @param string $content Content to set
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
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]; return explode('.', $this->name)[0];
} }
/**
* {@inheritdoc}
*/
public function getExtension() : string public function getExtension() : string
{ {
$extension = explode('.', $this->name); $extension = explode('.', $this->name);
@ -402,28 +364,77 @@ class File extends FileAbstract implements FileInterface
return $extension[1] ?? ''; return $extension[1] ?? '';
} }
/**
* {@inheritdoc}
*/
public function getParent() : ContainerInterface public function getParent() : ContainerInterface
{ {
// TODO: Implement getParent() method. // TODO: Implement getParent() method.
} }
public function copyNode() : bool /**
* {@inheritdoc}
*/
public function copyNode(string $to, bool $overwrite = false) : bool
{ {
// TODO: Implement copyNode() method. // TODO: Implement copyNode() method.
} }
public function moveNode() : bool /**
* {@inheritdoc}
*/
public function moveNode(string $to, bool $overwrite = false) : bool
{ {
// TODO: Implement moveNode() method. // TODO: Implement moveNode() method.
} }
/**
* {@inheritdoc}
*/
public function deleteNode() : bool public function deleteNode() : bool
{ {
// TODO: Implement deleteNode() method. // 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. // 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] ?? '';
}
} }

View File

@ -113,38 +113,23 @@ abstract class FileAbstract implements ContainerInterface
} }
/** /**
* Get directory/file count. * {@inheritdoc}
*
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function getCount() : int public function getCount(bool $recursive = true) : int
{ {
return $this->count; return $this->count;
} }
/** /**
* Get directory/file size. * {@inheritdoc}
*
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function getSize() : int public function getSize(bool $recursive = true) : int
{ {
return $this->size; return $this->size;
} }
/** /**
* Get name. * {@inheritdoc}
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function getName() : string public function getName() : string
{ {
@ -152,12 +137,7 @@ abstract class FileAbstract implements ContainerInterface
} }
/** /**
* Get path. * {@inheritdoc}
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function getPath() : string public function getPath() : string
{ {
@ -165,12 +145,7 @@ abstract class FileAbstract implements ContainerInterface
} }
/** /**
* Get parent directory. * {@inheritdoc}
*
* @return Directory
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function parentNode() : Directory public function parentNode() : Directory
{ {
@ -178,12 +153,7 @@ abstract class FileAbstract implements ContainerInterface
} }
/** /**
* Get created at. * {@inheritdoc}
*
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function getCreatedAt() : \DateTime public function getCreatedAt() : \DateTime
{ {
@ -191,12 +161,7 @@ abstract class FileAbstract implements ContainerInterface
} }
/** /**
* Get last changed at. * {@inheritdoc}
*
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function getChangedAt() : \DateTime public function getChangedAt() : \DateTime
{ {
@ -204,12 +169,7 @@ abstract class FileAbstract implements ContainerInterface
} }
/** /**
* Get owner. * {@inheritdoc}
*
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function getOwner() : int public function getOwner() : int
{ {
@ -217,12 +177,7 @@ abstract class FileAbstract implements ContainerInterface
} }
/** /**
* Get permission. * {@inheritdoc}
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function getPermission() : string public function getPermission() : string
{ {
@ -230,12 +185,7 @@ abstract class FileAbstract implements ContainerInterface
} }
/** /**
* (Re-)Index path. * {@inheritdoc}
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public function index() public function index()
{ {

View File

@ -15,7 +15,6 @@
*/ */
namespace phpOMS\System\File\Local; namespace phpOMS\System\File\Local;
use phpOMS\System\File\ContainerInterface; use phpOMS\System\File\ContainerInterface;
use phpOMS\System\File\FileInterface;
use phpOMS\System\File\StorageAbstract; use phpOMS\System\File\StorageAbstract;
/** /**
@ -33,127 +32,225 @@ use phpOMS\System\File\StorageAbstract;
*/ */
class LocalStorage extends StorageAbstract class LocalStorage extends StorageAbstract
{ {
/**
* {@inheritdoc}
*/
public static function created(string $path) : \DateTime public static function created(string $path) : \DateTime
{ {
// TODO: Implement created() method. // TODO: Implement created() method.
} }
/**
* {@inheritdoc}
*/
public static function changed(string $path) : \DateTime public static function changed(string $path) : \DateTime
{ {
// TODO: Implement changed() method. // TODO: Implement changed() method.
} }
/**
* {@inheritdoc}
*/
public static function owner(string $path) : int public static function owner(string $path) : int
{ {
// TODO: Implement owner() method. // TODO: Implement owner() method.
} }
public static function permission(string $path) : int /**
* {@inheritdoc}
*/
public static function permission(string $path) : string
{ {
// TODO: Implement permission() method. // TODO: Implement permission() method.
} }
/**
* {@inheritdoc}
*/
public static function parent(string $path) : string public static function parent(string $path) : string
{ {
// TODO: Implement parent() method. // TODO: Implement parent() method.
} }
/**
* {@inheritdoc}
*/
public static function create(string $path) : bool public static function create(string $path) : bool
{ {
// TODO: Implement create() method. // TODO: Implement create() method.
} }
/**
* {@inheritdoc}
*/
public static function delete(string $path) : bool public static function delete(string $path) : bool
{ {
// TODO: Implement delete() method. // TODO: Implement delete() method.
} }
/**
* {@inheritdoc}
*/
public static function copy(string $from, string $to, bool $overwrite = false) : bool public static function copy(string $from, string $to, bool $overwrite = false) : bool
{ {
// TODO: Implement copy() method. // TODO: Implement copy() method.
} }
/**
* {@inheritdoc}
*/
public static function move(string $from, string $to, bool $overwrite = false) : bool public static function move(string $from, string $to, bool $overwrite = false) : bool
{ {
// TODO: Implement move() method. // 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. // TODO: Implement size() method.
} }
/**
* {@inheritdoc}
*/
public static function exists(string $path) : bool public static function exists(string $path) : bool
{ {
// TODO: Implement exists() method. // 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. // TODO: Implement getCount() method.
} }
public function getSize() : int /**
* {@inheritdoc}
*/
public function getSize(bool $recursive = false) : int
{ {
// TODO: Implement getSize() method. // TODO: Implement getSize() method.
} }
/**
* {@inheritdoc}
*/
public function getName() : string public function getName() : string
{ {
// TODO: Implement getName() method. // TODO: Implement getName() method.
} }
/**
* {@inheritdoc}
*/
public function getPath() : string public function getPath() : string
{ {
// TODO: Implement getPath() method. // TODO: Implement getPath() method.
} }
/**
* {@inheritdoc}
*/
public function getParent() : ContainerInterface public function getParent() : ContainerInterface
{ {
// TODO: Implement getParent() method. // TODO: Implement getParent() method.
} }
/**
* {@inheritdoc}
*/
public function createNode() : bool public function createNode() : bool
{ {
// TODO: Implement createNode() method. // TODO: Implement createNode() method.
} }
public function copyNode() : bool /**
* {@inheritdoc}
*/
public function copyNode(string $to, bool $overwrite = false) : bool
{ {
// TODO: Implement copyNode() method. // TODO: Implement copyNode() method.
} }
public function moveNode() : bool /**
* {@inheritdoc}
*/
public function moveNode(string $to, bool $overwrite = false) : bool
{ {
// TODO: Implement moveNode() method. // TODO: Implement moveNode() method.
} }
/**
* {@inheritdoc}
*/
public function deleteNode() : bool public function deleteNode() : bool
{ {
// TODO: Implement deleteNode() method. // TODO: Implement deleteNode() method.
} }
/**
* {@inheritdoc}
*/
public function getCreatedAt() : \DateTime public function getCreatedAt() : \DateTime
{ {
// TODO: Implement getCreatedAt() method. // TODO: Implement getCreatedAt() method.
} }
/**
* {@inheritdoc}
*/
public function getChangedAt() : \DateTime public function getChangedAt() : \DateTime
{ {
// TODO: Implement getChangedAt() method. // TODO: Implement getChangedAt() method.
} }
/**
* {@inheritdoc}
*/
public function getOwner() : int public function getOwner() : int
{ {
// TODO: Implement getOwner() method. // TODO: Implement getOwner() method.
} }
/**
* {@inheritdoc}
*/
public function getPermission() : string public function getPermission() : string
{ {
// TODO: Implement getPermission() method. // TODO: Implement getPermission() method.
} }
/**
* {@inheritdoc}
*/
public function index() public function index()
{ {
// TODO: Implement index() method. // TODO: Implement index() method.
@ -161,7 +258,7 @@ class LocalStorage extends StorageAbstract
/** /**
* Return the current element * 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. * @return mixed Can return any type.
* @since 5.0.0 * @since 5.0.0
*/ */
@ -172,7 +269,7 @@ class LocalStorage extends StorageAbstract
/** /**
* Move forward to next element * 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. * @return void Any returned value is ignored.
* @since 5.0.0 * @since 5.0.0
*/ */
@ -183,7 +280,7 @@ class LocalStorage extends StorageAbstract
/** /**
* Return the key of the current element * 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. * @return mixed scalar on success, or null on failure.
* @since 5.0.0 * @since 5.0.0
*/ */
@ -194,7 +291,7 @@ class LocalStorage extends StorageAbstract
/** /**
* Checks if current position is valid * 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. * @return boolean The return value will be casted to boolean and then evaluated.
* Returns true on success or false on failure. * Returns true on success or false on failure.
* @since 5.0.0 * @since 5.0.0
@ -206,7 +303,7 @@ class LocalStorage extends StorageAbstract
/** /**
* Rewind the Iterator to the first element * 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. * @return void Any returned value is ignored.
* @since 5.0.0 * @since 5.0.0
*/ */
@ -217,14 +314,14 @@ class LocalStorage extends StorageAbstract
/** /**
* Whether a offset exists * 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 <p> * @param mixed $offset <p>
* An offset to check for. * An offset to check for.
* </p> * </p>
* @return boolean true on success or false on failure. * @return boolean true on success or false on failure.
* </p> * </p>
* <p> * <p>
* 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 * @since 5.0.0
*/ */
public function offsetExists($offset) public function offsetExists($offset)
@ -234,10 +331,10 @@ class LocalStorage extends StorageAbstract
/** /**
* Offset to retrieve * Offset to retrieve
* @link http://php.net/manual/en/arrayaccess.offsetget.php * @link http://php.net/manual/en/arrayaccess.offsetget.php
* @param mixed $offset <p> * @param mixed $offset <p>
* The offset to retrieve. * The offset to retrieve.
* </p> * </p>
* @return mixed Can return all value types. * @return mixed Can return all value types.
* @since 5.0.0 * @since 5.0.0
*/ */
@ -248,13 +345,13 @@ class LocalStorage extends StorageAbstract
/** /**
* Offset to set * Offset to set
* @link http://php.net/manual/en/arrayaccess.offsetset.php * @link http://php.net/manual/en/arrayaccess.offsetset.php
* @param mixed $offset <p> * @param mixed $offset <p>
* The offset to assign the value to. * The offset to assign the value to.
* </p> * </p>
* @param mixed $value <p> * @param mixed $value <p>
* The value to set. * The value to set.
* </p> * </p>
* @return void * @return void
* @since 5.0.0 * @since 5.0.0
*/ */
@ -265,10 +362,10 @@ class LocalStorage extends StorageAbstract
/** /**
* Offset to unset * Offset to unset
* @link http://php.net/manual/en/arrayaccess.offsetunset.php * @link http://php.net/manual/en/arrayaccess.offsetunset.php
* @param mixed $offset <p> * @param mixed $offset <p>
* The offset to unset. * The offset to unset.
* </p> * </p>
* @return void * @return void
* @since 5.0.0 * @since 5.0.0
*/ */
@ -277,28 +374,35 @@ class LocalStorage extends StorageAbstract
// TODO: Implement offsetUnset() method. // 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. // TODO: Implement put() method.
} }
/**
* {@inheritdoc}
*/
public static function get(string $path) : string public static function get(string $path) : string
{ {
// TODO: Implement get() method. // TODO: Implement get() method.
} }
public function putContent() : bool /**
* {@inheritdoc}
*/
public function putContent(string $content, int $mode = 0) : bool
{ {
// TODO: Implement putContent() method. // TODO: Implement putContent() method.
} }
/**
* {@inheritdoc}
*/
public function getContent() : string public function getContent() : string
{ {
// TODO: Implement getContent() method. // TODO: Implement getContent() method.
} }
protected function getType() : ContainerInterface
{
// TODO: Implement getType() method.
}
} }

View File

@ -37,25 +37,32 @@ final class Storage
* @since 1.0.0 * @since 1.0.0
*/ */
private static $registered = []; private static $registered = [];
private function __construct()
{
}
/** /**
* Get registred env instance. * Get registred env instance.
* *
* @param string $env Environment name * @param string $env Environment name
* *
* @return StorageAbstract
*
* @throws \Exception Throws exception in case of invalid storage * @throws \Exception Throws exception in case of invalid storage
* *
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
public static function env(string $env = 'local') : string public static function env(string $env = 'local') : StorageAbstract
{ {
if (isset(self::$registered[$env])) { if (isset(self::$registered[$env])) {
if(is_string(self::$registered[$env])) { if(is_string(self::$registered[$env])) {
$env = self::$registered[$env]::getInstance(); $env = self::$registered[$env]::getInstance();
} elseif(self::$registered[$env] instanceof StorageAbstract) { } elseif(self::$registered[$env] instanceof StorageAbstract) {
$env = self::$registered[$env]::getInstance(); $env = self::$registered[$env]::getInstance();
} elseif(self::$regsitered[$env] instanceof ContainerInterface) { } elseif(self::$registered[$env] instanceof ContainerInterface) {
$env = self::$registered[$env]; $env = self::$registered[$env];
} else { } else {
throw new \Exception('Invalid type'); throw new \Exception('Invalid type');
@ -75,6 +82,8 @@ final class Storage
* @param string $name Name of the 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. * @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 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */