Add dummy ftp functions and tests

This commit is contained in:
Dennis Eichhorn 2017-11-20 01:30:53 +01:00
parent 4ca9870b82
commit 0cc736b0ff
5 changed files with 223 additions and 652 deletions

View File

@ -30,6 +30,7 @@ use phpOMS\System\File\Local\Directory as DirectoryLocal;
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://website.orange-management.de * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
* @codeCoverageIgnore
*/ */
class Directory extends FileAbstract implements DirectoryInterface class Directory extends FileAbstract implements DirectoryInterface
{ {

View File

@ -21,34 +21,56 @@ use phpOMS\System\File\FileInterface;
use phpOMS\System\File\PathException; use phpOMS\System\File\PathException;
use phpOMS\System\File\Local\File as FileLocal; use phpOMS\System\File\Local\File as FileLocal;
use phpOMS\System\File\Local\FileAbstract; 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. * 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 * @category Framework
* @package phpOMS\System\File * @package phpOMS\System\File
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://website.orange-management.de * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
* @codeCoverageIgnore
*/ */
class File extends FileAbstract implements FileInterface 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} * {@inheritdoc}
*/ */
public static function put(string $path, string $content, int $mode = ContentPutMode::REPLACE | ContentPutMode::CREATE) : bool 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 $http = new Http($path);
$current = ftp_pwd($con); $con = self::ftpConnect($http);
if (!ftp_chdir($con, File::dirpath($path))) {
if (ftp_pwd($con) !== $http->getPath()) {
return false; return false;
} }
$exists = self::exists($path); $exists = self::ftpExists($con, $http);
$result = false;
if ( if (
(($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists) (($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists)
@ -56,20 +78,26 @@ class File extends FileAbstract implements FileInterface
|| (($mode & ContentPutMode::REPLACE) === ContentPutMode::REPLACE && $exists) || (($mode & ContentPutMode::REPLACE) === ContentPutMode::REPLACE && $exists)
|| (!$exists && ($mode & ContentPutMode::CREATE) === ContentPutMode::CREATE) || (!$exists && ($mode & ContentPutMode::CREATE) === ContentPutMode::CREATE)
) { ) {
if (!Directory::exists(dirname($path))) { if (($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists) {
Directory::create(dirname($path), 0755, true); 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_close($con);
ftp_fput($path, $content);
fclose($stream);
$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 public static function get(string $path) : /* ? */string
{ {
$temp = fopen('php://temp', 'r+'); $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)) { if (ftp_chdir($con, File::dirpath($path)) && ftp_fget($con, $temp, $path, FTP_BINARY, 0)) {
rewind($temp); rewind($temp);
$content = stream_get_contents($temp); $content = stream_get_contents($temp);
} }
fclose($temp); fclose($temp);
ftp_chdir($current);
return $content ?? null; return $content ?? null;
} }
@ -120,18 +149,13 @@ class File extends FileAbstract implements FileInterface
*/ */
public static function exists(string $path) : bool public static function exists(string $path) : bool
{ {
$http = new Http($path);
$con = self::ftpConnect($http);
$exists = self::ftpExists($con, $http->getPath());
if (($current = ftp_pwd($con)) !== LocalFile::dirpath($path)) { fclose($con);
if (!ftp_chdir($con, $path)) {
return false;
}
}
$list = ftp_nlist($con, $path); return $exists;
ftp_chdir($con, $current);
return in_array($path, $list);
} }
/** /**
@ -163,8 +187,13 @@ class File extends FileAbstract implements FileInterface
*/ */
public static function changed(string $path) : \DateTime public static function changed(string $path) : \DateTime
{ {
$http = new Http($path);
$con = self::ftpConnect($http);
$changed = new \DateTime(); $changed = new \DateTime();
$changed->setTimestamp(ftp_mdtm($con, $path));
$changed->setTimestamp(ftp_mdtm($con, $http->getPath()));
fclose($con);
return $changed; return $changed;
} }
@ -174,11 +203,18 @@ class File extends FileAbstract implements FileInterface
*/ */
public static function size(string $path, bool $recursive = true) : int 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); 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 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 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) { foreach ($files as $fileData) {
if (strpos($fileData, self::name($path)) !== false) { if (strpos($fileData, self::name($path)) !== false) {
$chunks = preg_split("/\s+/", $fileData); $chunks = preg_split("/\s+/", $fileData);
$items['permission'] = $chungs[0]; $items['permission'] = $chunks[0];
$items['user'] = $chungs[2]; $items['user'] = $chunks[2];
$items['group'] = $chungs[3]; $items['group'] = $chunks[3];
$items['size'] = $chungs[4]; $items['size'] = $chunks[4];
$items['type'] = $chunks[0][0] === 'd' ? 'directory' : 'file'; $items['type'] = $chunks[0][0] === 'd' ? 'directory' : 'file';
break; break;
@ -253,6 +301,8 @@ class File extends FileAbstract implements FileInterface
*/ */
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: handle different ftp connections AND local to ftp
if (($src = self::get($from)) === false) { if (($src = self::get($from)) === false) {
return 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 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); throw new PathException($from);
} }
@ -274,9 +328,14 @@ class File extends FileAbstract implements FileInterface
Directory::create(dirname($to), 0755, true); 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; return false;
} }
@ -285,11 +344,15 @@ class File extends FileAbstract implements FileInterface
*/ */
public static function delete(string $path) : bool 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; return false;
} }
ftp_delete($con, $path); ftp_delete($con, $path);
fclose($con);
return true; return true;
} }

View File

@ -14,8 +14,8 @@
declare(strict_types = 1); declare(strict_types = 1);
namespace phpOMS\System\File\Ftp; namespace phpOMS\System\File\Ftp;
use phpOMS\System\File\ContainerInterface;
use phpOMS\System\File\StorageAbstract; use phpOMS\System\File\StorageAbstract;
use phpOMS\System\File\PathException;
/** /**
* Filesystem class. * Filesystem class.
@ -27,11 +27,10 @@ use phpOMS\System\File\StorageAbstract;
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://website.orange-management.de * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
* @codeCoverageIgnore
*/ */
class FtpStorage extends StorageAbstract class FtpStorage extends StorageAbstract
{ {
private $con = null;
private static $instance = null; private static $instance = null;
public function __construct() { public function __construct() {
@ -47,393 +46,9 @@ class FtpStorage extends StorageAbstract
return self::$instance; 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) { return is_dir($path) || (!is_file($path) && stripos($path, '.') === false) ? Directory::class : File::class;
$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 <p>
* An offset to check for.
* </p>
* @return boolean true on success or false on failure.
* </p>
* <p>
* 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 <p>
* The offset to retrieve.
* </p>
* @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 <p>
* The offset to assign the value to.
* </p>
* @param mixed $value <p>
* The value to set.
* </p>
* @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 <p>
* The offset to unset.
* </p>
* @return void
* @since 5.0.0
*/
public function offsetUnset($offset)
{
// TODO: Implement offsetUnset() method.
} }
/** /**
@ -441,7 +56,11 @@ class FtpStorage extends StorageAbstract
*/ */
public static function put(string $path, string $content, int $mode = 0) : bool 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 public static function get(string $path) : string
{ {
// TODO: Implement get() method. if (is_dir($path)) {
throw new PathException($path);
}
return File::get($path);
} }
/** /**
* {@inheritdoc} * {@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} * {@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);
}
/** return Directory::list($path, $filter);
* {@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.
} }
/** /**
@ -497,7 +100,11 @@ class FtpStorage extends StorageAbstract
*/ */
public static function set(string $path, string $content) : bool 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 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 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 public static function extension(string $path) : string
{ {
// TODO: Implement extension() method. if (is_dir($path)) {
} throw new PathException($path);
}
/** return File::extension($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.
} }
} }

View File

@ -45,139 +45,11 @@ class LocalStorage extends StorageAbstract
return self::$instance; 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; 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} * {@inheritdoc}
*/ */
@ -217,9 +89,9 @@ class LocalStorage extends StorageAbstract
/** /**
* {@inheritdoc} * {@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);
} }
/** /**

View File

@ -72,27 +72,42 @@ abstract class StorageAbstract
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
abstract public static function created(string $path) : \DateTime; public static function created(string $path) : \DateTime
{
return static::getClassType($path)::created($path);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
abstract public static function changed(string $path) : \DateTime; public static function changed(string $path) : \DateTime
{
return static::getClassType($path)::changed($path);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
abstract public static function owner(string $path) : int; public static function owner(string $path) : int
{
return static::getClassType($path)::owner($path);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
abstract public static function permission(string $path) : int; public static function permission(string $path) : int
{
return static::getClassType($path)::permission($path);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
abstract public static function parent(string $path) : string; public static function parent(string $path) : string
{
return static::getClassType($path)::parent($path);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -102,58 +117,96 @@ abstract class StorageAbstract
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
abstract public static function delete(string $path) : bool; public static function delete(string $path) : bool
{
return static::getClassType($path)::delete($path);
}
/** /**
* {@inheritdoc} * {@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} * {@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} * {@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} * {@inheritdoc}
*/ */
abstract public static function exists(string $path) : bool; public static function exists(string $path) : bool
{
return static::getClassType($path)::exists($path);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
abstract public static function name(string $path) : string; public static function name(string $path) : string
{
return static::getClassType($path)::name($path);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
abstract public static function basename(string $path) : string; public static function basename(string $path) : string
{
return static::getClassType($path)::basename($path);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
abstract public static function dirname(string $path) : string; public static function dirname(string $path) : string
{
return static::getClassType($path)::dirname($path);
}
/** /**
* {@inheritdoc} * {@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} * {@inheritdoc}
*/ */
abstract public static function list(string $path, string $filter = '*') : array; 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} * {@inheritdoc}
*/ */
@ -164,11 +217,6 @@ abstract class StorageAbstract
*/ */
abstract public static function get(string $path) : string; abstract public static function get(string $path) : string;
/**
* {@inheritdoc}
*/
abstract public static function sanitize(string $path, string $replace = '') : string;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */