From 0cc736b0ff64fda65c3ae7648571c8722b7c62b2 Mon Sep 17 00:00:00 2001
From: Dennis Eichhorn
Date: Mon, 20 Nov 2017 01:30:53 +0100
Subject: [PATCH] Add dummy ftp functions and tests
---
System/File/Ftp/Directory.php | 1 +
System/File/Ftp/File.php | 149 ++++++---
System/File/Ftp/FtpStorage.php | 495 +++--------------------------
System/File/Local/LocalStorage.php | 134 +-------
System/File/StorageAbstract.php | 96 ++++--
5 files changed, 223 insertions(+), 652 deletions(-)
diff --git a/System/File/Ftp/Directory.php b/System/File/Ftp/Directory.php
index 877d2f51a..7343b0191 100644
--- a/System/File/Ftp/Directory.php
+++ b/System/File/Ftp/Directory.php
@@ -30,6 +30,7 @@ use phpOMS\System\File\Local\Directory as DirectoryLocal;
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
+ * @codeCoverageIgnore
*/
class Directory extends FileAbstract implements DirectoryInterface
{
diff --git a/System/File/Ftp/File.php b/System/File/Ftp/File.php
index c0e2d6430..23f21af34 100644
--- a/System/File/Ftp/File.php
+++ b/System/File/Ftp/File.php
@@ -21,34 +21,56 @@ use phpOMS\System\File\FileInterface;
use phpOMS\System\File\PathException;
use phpOMS\System\File\Local\File as FileLocal;
use phpOMS\System\File\Local\FileAbstract;
-use phpOMS\System\File\Local\Directory as DirectoryLocal;
+use phpOMS\System\File\Local\Directory as LocalDirectory;
+use phpOMS\System\File\Local\File as LocalFile;
+use phpOMS\Uri\Http;
/**
* Filesystem class.
*
- * Performing operations on the file system
+ * Performing operations on the file system.
+ *
+ * All static implementations require a path/uri in the following form: ftp://user:pass@domain.com/path/subpath...
*
* @category Framework
* @package phpOMS\System\File
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
+ * @codeCoverageIgnore
*/
class File extends FileAbstract implements FileInterface
{
+ public static function ftpConnect(Http $http)
+ {
+ $con = ftp_connect($http->getBase() . $http->getPath(), $http->getPort());
+
+ ftp_login($con, $http->getUser(), $http->getPass());
+ ftp_chdir($con, $http->getPath()); // todo: is this required ?
+
+ return $con;
+ }
+
+ public static function ftpExists($con, string $path)
+ {
+ $list = ftp_nlist($con, LocalFile::dirpath($path));
+
+ return in_array(LocalFile::basename($path), $list);
+ }
+
/**
* {@inheritdoc}
*/
public static function put(string $path, string $content, int $mode = ContentPutMode::REPLACE | ContentPutMode::CREATE) : bool
{
- // todo: create all else cases, right now all getting handled the same way which is wrong
- $current = ftp_pwd($con);
- if (!ftp_chdir($con, File::dirpath($path))) {
+ $http = new Http($path);
+ $con = self::ftpConnect($http);
+
+ if (ftp_pwd($con) !== $http->getPath()) {
return false;
}
- $exists = self::exists($path);
- $result = false;
+ $exists = self::ftpExists($con, $http);
if (
(($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists)
@@ -56,20 +78,26 @@ class File extends FileAbstract implements FileInterface
|| (($mode & ContentPutMode::REPLACE) === ContentPutMode::REPLACE && $exists)
|| (!$exists && ($mode & ContentPutMode::CREATE) === ContentPutMode::CREATE)
) {
- if (!Directory::exists(dirname($path))) {
- Directory::create(dirname($path), 0755, true);
+ if (($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists) {
+ file_put_contents($path, file_get_contents($path) . $content, 0, stream_context_create(['ftp' => ['overwrite' => true]]));
+ } elseif (($mode & ContentPutMode::PREPEND) === ContentPutMode::PREPEND && $exists) {
+ file_put_contents($path, $content . file_get_contents($path), 0, stream_context_create(['ftp' => ['overwrite' => true]]));
+ } else {
+ if (!Directory::ftpExists($con, dirname($path))) {
+ Directory::ftpCreate($con, dirname($path), 0755, true);
+ }
+
+ file_put_contents($path, $content, 0, stream_context_create(['ftp' => ['overwrite' => true]]));
}
- $stream = fopen('data://temp,' . $content, 'r');
- ftp_fput($path, $content);
- fclose($stream);
+ ftp_close($con);
- $result = true;
+ return true;
}
- ftp_chdir($current);
+ ftp_close($con);
- return $result;
+ return false;
}
/**
@@ -78,15 +106,16 @@ class File extends FileAbstract implements FileInterface
public static function get(string $path) : /* ? */string
{
$temp = fopen('php://temp', 'r+');
+ $http = new Http($path);
+
+ $con = self::ftpConnect($http);
- $current = ftp_pwd($con);
if (ftp_chdir($con, File::dirpath($path)) && ftp_fget($con, $temp, $path, FTP_BINARY, 0)) {
rewind($temp);
$content = stream_get_contents($temp);
}
fclose($temp);
- ftp_chdir($current);
return $content ?? null;
}
@@ -120,18 +149,13 @@ class File extends FileAbstract implements FileInterface
*/
public static function exists(string $path) : bool
{
-
- if (($current = ftp_pwd($con)) !== LocalFile::dirpath($path)) {
- if (!ftp_chdir($con, $path)) {
- return false;
- }
- }
+ $http = new Http($path);
+ $con = self::ftpConnect($http);
+ $exists = self::ftpExists($con, $http->getPath());
- $list = ftp_nlist($con, $path);
+ fclose($con);
- ftp_chdir($con, $current);
-
- return in_array($path, $list);
+ return $exists;
}
/**
@@ -163,8 +187,13 @@ class File extends FileAbstract implements FileInterface
*/
public static function changed(string $path) : \DateTime
{
+ $http = new Http($path);
+ $con = self::ftpConnect($http);
$changed = new \DateTime();
- $changed->setTimestamp(ftp_mdtm($con, $path));
+
+ $changed->setTimestamp(ftp_mdtm($con, $http->getPath()));
+
+ fclose($con);
return $changed;
}
@@ -174,11 +203,18 @@ class File extends FileAbstract implements FileInterface
*/
public static function size(string $path, bool $recursive = true) : int
{
- if (!self::exists($path)) {
+ $http = new Http($path);
+ $con = self::ftpConnect($http);
+
+ if (!self::exists($http->getPath())) {
throw new PathException($path);
}
- return ftp_size($con, $path);
+ $size = ftp_size($con, $http->getPath());
+
+ fclose($con);
+
+ return $size;
}
/**
@@ -186,7 +222,13 @@ class File extends FileAbstract implements FileInterface
*/
public static function owner(string $path) : int
{
- return self::parseFtpFileData($path)['user'] ?? '';
+ $http = new Http($path);
+ $con = self::ftpConnect($http);
+ $owner = self::parseFtpFileData($con, $path)['user'] ?? '';
+
+ fclose($con);
+
+ return $owner;
}
/**
@@ -194,22 +236,28 @@ class File extends FileAbstract implements FileInterface
*/
public static function permission(string $path) : int
{
- return (int) self::parseFtpFileData($path)['permission'] ?? 0;
+ $http = new Http($path);
+ $con = self::ftpConnect($http);
+ $permission = (int) self::parseFtpFileData($con, $path)['permission'] ?? 0;
+
+ fclose($con);
+
+ return $permission;
}
- private static function parseFtpFileData(string $path) : array
+ private static function parseFtpFileData($con, string $path) : array
{
- $items = [];
+ $items = [];
- if (is_array($files = ftp_rawlist($con, self::dirpath($path)))) {
+ if (is_array($files = ftp_rawlist($con, LocalFile::dirpath($path)))) {
foreach ($files as $fileData) {
if (strpos($fileData, self::name($path)) !== false) {
- $chunks = preg_split("/\s+/", $fileData);
+ $chunks = preg_split("/\s+/", $fileData);
- $items['permission'] = $chungs[0];
- $items['user'] = $chungs[2];
- $items['group'] = $chungs[3];
- $items['size'] = $chungs[4];
+ $items['permission'] = $chunks[0];
+ $items['user'] = $chunks[2];
+ $items['group'] = $chunks[3];
+ $items['size'] = $chunks[4];
$items['type'] = $chunks[0][0] === 'd' ? 'directory' : 'file';
break;
@@ -253,6 +301,8 @@ class File extends FileAbstract implements FileInterface
*/
public static function copy(string $from, string $to, bool $overwrite = false) : bool
{
+ // todo: handle different ftp connections AND local to ftp
+
if (($src = self::get($from)) === false) {
return false;
}
@@ -265,7 +315,11 @@ class File extends FileAbstract implements FileInterface
*/
public static function move(string $from, string $to, bool $overwrite = false) : bool
{
- if (!self::exists($from)) {
+ // todo: handle different ftp connections AND local to ftp
+ $http = new Http($to);
+ $con = self::ftpConnect($http);
+
+ if (!self::ftpExists($con, $from)) {
throw new PathException($from);
}
@@ -274,9 +328,14 @@ class File extends FileAbstract implements FileInterface
Directory::create(dirname($to), 0755, true);
}
- return ftp_rename($con, $from, $to);
+ $rename = ftp_rename($con, $from, $to);
+ fclose($con);
+
+ return $rename;
}
+ fclose($con);
+
return false;
}
@@ -285,11 +344,15 @@ class File extends FileAbstract implements FileInterface
*/
public static function delete(string $path) : bool
{
- if (!self::exists($path)) {
+ $http = new Http($path);
+ $con = self::ftpConnect($http);
+
+ if (!self::ftpExists($con, $path)) {
return false;
}
ftp_delete($con, $path);
+ fclose($con);
return true;
}
diff --git a/System/File/Ftp/FtpStorage.php b/System/File/Ftp/FtpStorage.php
index c6e1a597a..4e8677afc 100644
--- a/System/File/Ftp/FtpStorage.php
+++ b/System/File/Ftp/FtpStorage.php
@@ -14,8 +14,8 @@
declare(strict_types = 1);
namespace phpOMS\System\File\Ftp;
-use phpOMS\System\File\ContainerInterface;
use phpOMS\System\File\StorageAbstract;
+use phpOMS\System\File\PathException;
/**
* Filesystem class.
@@ -27,15 +27,14 @@ use phpOMS\System\File\StorageAbstract;
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
+ * @codeCoverageIgnore
*/
class FtpStorage extends StorageAbstract
{
- private $con = null;
-
private static $instance = null;
public function __construct() {
-
+
}
public static function getInstance() : StorageAbstract
@@ -47,393 +46,9 @@ class FtpStorage extends StorageAbstract
return self::$instance;
}
- public function connect(string $uri, int $port = 21, bool $mode = true, string $login = null, string $pass = null, bool $ssl = false) : bool
+ protected static function getClassType(string $path) : string
{
- if ($ssl) {
- $this->con = ftp_connect($uri, $port);
- } else {
- $this->con = ftp_ssl_connect($uri, $port);
- }
-
- ftp_pasv($this->con, $mode);
-
- if (isset($login, $pass)) {
- ftp_login($this->con, $login, $pass);
- }
- }
-
- public function __destruct()
- {
- if (isset($this->con)) {
- ftp_close($this->con);
- $this->con = null;
- }
- }
-
- /**
- * {@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.
- }
-
- /**
- * {@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.
- }
-
- /**
- * {@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.
- }
-
- /**
- * {@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 dirname(string $path) : string
- {
- // TODO: Implement basename() method.
- }
-
- /**
- * {@inheritdoc}
- */
- public static function dirpath(string $path) : string
- {
- // TODO: Implement basename() method.
- }
-
- /**
- * {@inheritdoc}
- */
- public static function list(string $path, string $filter = '*') : array
- {
- // TODO: Implement basename() method.
- }
-
- /**
- * {@inheritdoc}
- */
- public static function count(string $path, bool $recursive = true, array $ignore = []) : int
- {
- // TODO: Implement count() method.
- }
-
- /**
- * {@inheritdoc}
- */
- public function getCount(bool $recursive = false) : int
- {
- // TODO: Implement getCount() method.
- }
-
- /**
- * {@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.
- }
-
- /**
- * {@inheritdoc}
- */
- public function copyNode(string $to, bool $overwrite = false) : bool
- {
- // TODO: Implement copyNode() method.
- }
-
- /**
- * {@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.
- }
-
- /**
- * Return the current element
- * @link http://php.net/manual/en/iterator.current.php
- * @return mixed Can return any type.
- * @since 5.0.0
- */
- public function current()
- {
- // TODO: Implement current() method.
- }
-
- /**
- * Move forward to next element
- * @link http://php.net/manual/en/iterator.next.php
- * @return void Any returned value is ignored.
- * @since 5.0.0
- */
- public function next()
- {
- // TODO: Implement next() method.
- }
-
- /**
- * Return the key of the current element
- * @link http://php.net/manual/en/iterator.key.php
- * @return mixed scalar on success, or null on failure.
- * @since 5.0.0
- */
- public function key()
- {
- // TODO: Implement key() method.
- }
-
- /**
- * Checks if current position is valid
- * @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
- */
- public function valid()
- {
- // TODO: Implement valid() method.
- }
-
- /**
- * Rewind the Iterator to the first element
- * @link http://php.net/manual/en/iterator.rewind.php
- * @return void Any returned value is ignored.
- * @since 5.0.0
- */
- public function rewind()
- {
- // TODO: Implement rewind() method.
- }
-
- /**
- * Whether a offset exists
- * @link http://php.net/manual/en/arrayaccess.offsetexists.php
- * @param mixed $offset
- * 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.
- * @since 5.0.0
- */
- public function offsetExists($offset)
- {
- // TODO: Implement offsetExists() method.
- }
-
- /**
- * 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 offsetGet() method.
- }
-
- /**
- * Offset to set
- * @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.
- *
- * @return void
- * @since 5.0.0
- */
- public function offsetSet($offset, $value)
- {
- // TODO: Implement offsetSet() method.
- }
-
- /**
- * Offset to unset
- * @link http://php.net/manual/en/arrayaccess.offsetunset.php
- * @param mixed $offset
- * The offset to unset.
- *
- * @return void
- * @since 5.0.0
- */
- public function offsetUnset($offset)
- {
- // TODO: Implement offsetUnset() method.
+ return is_dir($path) || (!is_file($path) && stripos($path, '.') === false) ? Directory::class : File::class;
}
/**
@@ -441,7 +56,11 @@ class FtpStorage extends StorageAbstract
*/
public static function put(string $path, string $content, int $mode = 0) : bool
{
- // TODO: Implement put() method.
+ if (is_dir($path)) {
+ throw new PathException($path);
+ }
+
+ return File::put($path, $content, $mode);
}
/**
@@ -449,47 +68,31 @@ class FtpStorage extends StorageAbstract
*/
public static function get(string $path) : string
{
- // TODO: Implement get() method.
+ if (is_dir($path)) {
+ throw new PathException($path);
+ }
+
+ return File::get($path);
}
/**
* {@inheritdoc}
*/
- public function putContent(string $content, int $mode = 0) : bool
+ public static function create(string $path) : bool
{
- // TODO: Implement putContent() method.
+ return stripos($path, '.') === false ? Directory::create($path, 0755, true) : File::create($path);
}
/**
* {@inheritdoc}
*/
- public function getContent() : string
+ public static function list(string $path, string $filter = '*') : array
{
- // TODO: Implement getContent() method.
- }
+ if (is_file($path)) {
+ throw new PathException($path);
+ }
- /**
- * {@inheritdoc}
- */
- public static function sanitize(string $path, string $replace = '') : string
- {
- // TODO: Implement sanitize() method.
- }
-
- /**
- * {@inheritdoc}
- */
- public function getNode(string $name)
- {
- // TODO: Implement getNode() method.
- }
-
- /**
- * {@inheritdoc}
- */
- public function addNode($file) : bool
- {
- // TODO: Implement addNode() method.
+ return Directory::list($path, $filter);
}
/**
@@ -497,7 +100,11 @@ class FtpStorage extends StorageAbstract
*/
public static function set(string $path, string $content) : bool
{
- // TODO: Implement set() method.
+ if (is_dir($path)) {
+ throw new PathException($path);
+ }
+
+ return File::set($path, $content);
}
/**
@@ -505,7 +112,11 @@ class FtpStorage extends StorageAbstract
*/
public static function append(string $path, string $content) : bool
{
- // TODO: Implement append() method.
+ if (is_dir($path)) {
+ throw new PathException($path);
+ }
+
+ return File::append($path, $content);
}
/**
@@ -513,7 +124,11 @@ class FtpStorage extends StorageAbstract
*/
public static function prepend(string $path, string $content) : bool
{
- // TODO: Implement prepend() method.
+ if (is_dir($path)) {
+ throw new PathException($path);
+ }
+
+ return File::prepend($path, $content);
}
/**
@@ -521,38 +136,10 @@ class FtpStorage extends StorageAbstract
*/
public static function extension(string $path) : string
{
- // TODO: Implement extension() method.
- }
+ if (is_dir($path)) {
+ throw new PathException($path);
+ }
- /**
- * {@inheritdoc}
- */
- public function setContent(string $content) : bool
- {
- // TODO: Implement setContent() method.
- }
-
- /**
- * {@inheritdoc}
- */
- public function appendContent(string $content) : bool
- {
- // TODO: Implement appendContent() method.
- }
-
- /**
- * {@inheritdoc}
- */
- public function prependContent(string $content) : bool
- {
- // TODO: Implement prependContent() method.
- }
-
- /**
- * {@inheritdoc}
- */
- public function getExtension() : string
- {
- // TODO: Implement getExtension() method.
+ return File::extension($path);
}
}
\ No newline at end of file
diff --git a/System/File/Local/LocalStorage.php b/System/File/Local/LocalStorage.php
index af70e5dc7..72e02302c 100644
--- a/System/File/Local/LocalStorage.php
+++ b/System/File/Local/LocalStorage.php
@@ -45,139 +45,11 @@ class LocalStorage extends StorageAbstract
return self::$instance;
}
- private static function getClassType(string $path) : string
+ protected static function getClassType(string $path) : string
{
return is_dir($path) || (!is_file($path) && stripos($path, '.') === false) ? Directory::class : File::class;
}
- /**
- * {@inheritdoc}
- */
- public static function created(string $path) : \DateTime
- {
- return self::getClassType($path)::created($path);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function changed(string $path) : \DateTime
- {
- return self::getClassType($path)::changed($path);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function owner(string $path) : int
- {
- return self::getClassType($path)::owner($path);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function permission(string $path) : int
- {
- return self::getClassType($path)::permission($path);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function parent(string $path) : string
- {
- return self::getClassType($path)::parent($path);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function create(string $path) : bool
- {
- return stripos($path, '.') === false ? Directory::create($path, 0755, true) : File::create($path);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function delete(string $path) : bool
- {
- return self::getClassType($path)::delete($path);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function copy(string $from, string $to, bool $overwrite = false) : bool
- {
- return self::getClassType($from)::copy($from, $to, $overwrite);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function move(string $from, string $to, bool $overwrite = false) : bool
- {
- return self::getClassType($from)::move($from, $to, $overwrite);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function size(string $path, bool $recursive = true) : int
- {
- return self::getClassType($path)::size($path, $recursive);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function exists(string $path) : bool
- {
- return self::getClassType($path)::exists($path);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function name(string $path) : string
- {
- return self::getClassType($path)::name($path);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function basename(string $path) : string
- {
- return self::getClassType($path)::basename($path);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function dirname(string $path) : string
- {
- return self::getClassType($path)::dirname($path);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function dirpath(string $path) : string
- {
- return self::getClassType($path)::dirpath($path);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function count(string $path, bool $recursive = true, array $ignore = []) : int
- {
- return self::getClassType($path)::count($path, $recursive, $ignore);
- }
-
/**
* {@inheritdoc}
*/
@@ -217,9 +89,9 @@ class LocalStorage extends StorageAbstract
/**
* {@inheritdoc}
*/
- public static function sanitize(string $path, string $replace = '') : string
+ public static function create(string $path) : bool
{
- return self::getClassType($path)::sanitize($path, $replace);
+ return stripos($path, '.') === false ? Directory::create($path, 0755, true) : File::create($path);
}
/**
diff --git a/System/File/StorageAbstract.php b/System/File/StorageAbstract.php
index de8828f86..7dffda6a0 100644
--- a/System/File/StorageAbstract.php
+++ b/System/File/StorageAbstract.php
@@ -72,27 +72,42 @@ abstract class StorageAbstract
/**
* {@inheritdoc}
*/
- abstract public static function created(string $path) : \DateTime;
+ public static function created(string $path) : \DateTime
+ {
+ return static::getClassType($path)::created($path);
+ }
/**
* {@inheritdoc}
*/
- abstract public static function changed(string $path) : \DateTime;
+ public static function changed(string $path) : \DateTime
+ {
+ return static::getClassType($path)::changed($path);
+ }
/**
* {@inheritdoc}
*/
- abstract public static function owner(string $path) : int;
+ public static function owner(string $path) : int
+ {
+ return static::getClassType($path)::owner($path);
+ }
/**
* {@inheritdoc}
*/
- abstract public static function permission(string $path) : int;
+ public static function permission(string $path) : int
+ {
+ return static::getClassType($path)::permission($path);
+ }
/**
* {@inheritdoc}
*/
- abstract public static function parent(string $path) : string;
+ public static function parent(string $path) : string
+ {
+ return static::getClassType($path)::parent($path);
+ }
/**
* {@inheritdoc}
@@ -102,58 +117,96 @@ abstract class StorageAbstract
/**
* {@inheritdoc}
*/
- abstract public static function delete(string $path) : bool;
+ public static function delete(string $path) : bool
+ {
+ return static::getClassType($path)::delete($path);
+ }
/**
* {@inheritdoc}
*/
- abstract public static function copy(string $from, string $to, bool $overwrite = false) : bool;
+ public static function copy(string $from, string $to, bool $overwrite = false) : bool
+ {
+ return static::getClassType($from)::copy($from, $to, $overwrite);
+ }
/**
* {@inheritdoc}
*/
- abstract public static function move(string $from, string $to, bool $overwrite = false) : bool;
+ public static function move(string $from, string $to, bool $overwrite = false) : bool
+ {
+ return static::getClassType($from)::move($from, $to, $overwrite);
+ }
/**
* {@inheritdoc}
*/
- abstract public static function size(string $path, bool $recursive = true) : int;
+ public static function size(string $path, bool $recursive = true) : int
+ {
+ return static::getClassType($path)::size($path, $recursive);
+ }
/**
* {@inheritdoc}
*/
- abstract public static function exists(string $path) : bool;
+ public static function exists(string $path) : bool
+ {
+ return static::getClassType($path)::exists($path);
+ }
/**
* {@inheritdoc}
*/
- abstract public static function name(string $path) : string;
+ public static function name(string $path) : string
+ {
+ return static::getClassType($path)::name($path);
+ }
/**
* {@inheritdoc}
*/
- abstract public static function basename(string $path) : string;
+ public static function basename(string $path) : string
+ {
+ return static::getClassType($path)::basename($path);
+ }
/**
* {@inheritdoc}
*/
- abstract public static function dirname(string $path) : string;
+ public static function dirname(string $path) : string
+ {
+ return static::getClassType($path)::dirname($path);
+ }
/**
* {@inheritdoc}
*/
- abstract public static function dirpath(string $path) : string;
+ public static function dirpath(string $path) : string
+ {
+ return static::getClassType($path)::dirpath($path);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function count(string $path, bool $recursive = true, array $ignore = []) : int
+ {
+ return static::getClassType($path)::count($path, $recursive, $ignore);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function sanitize(string $path, string $replace = '') : string
+ {
+ return static::getClassType($path)::sanitize($path, $replace);
+ }
/**
* {@inheritdoc}
*/
abstract public static function list(string $path, string $filter = '*') : array;
- /**
- * {@inheritdoc}
- */
- abstract public static function count(string $path, bool $recursive = true, array $ignore = []) : int;
-
/**
* {@inheritdoc}
*/
@@ -164,11 +217,6 @@ abstract class StorageAbstract
*/
abstract public static function get(string $path) : string;
- /**
- * {@inheritdoc}
- */
- abstract public static function sanitize(string $path, string $replace = '') : string;
-
/**
* {@inheritdoc}
*/