diff --git a/System/File/ContainerInterface.php b/System/File/ContainerInterface.php index 4bfbc08cc..640665651 100644 --- a/System/File/ContainerInterface.php +++ b/System/File/ContainerInterface.php @@ -193,6 +193,18 @@ interface ContainerInterface */ public static function basename(string $path) : string; + /** + * Make name/path operating system safe. + * + * @param string $path Path of the resource + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function sanitize(string $path) : string; + /** * Get amount of sub-resources. * diff --git a/System/File/DirectoryInterface.php b/System/File/DirectoryInterface.php index c6c09cbdf..5d9445f41 100644 --- a/System/File/DirectoryInterface.php +++ b/System/File/DirectoryInterface.php @@ -44,7 +44,7 @@ interface DirectoryInterface extends ContainerInterface, \Iterator, \ArrayAccess * @since 1.0.0 * @author Dennis Eichhorn */ - public static function count(string $path, bool $recursive = false, array $ignore = []) : int; + public static function count(string $path, bool $recursive = true, array $ignore = []) : int; /** * Get node by name. diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index 2ef75b9ee..140094950 100644 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -130,7 +130,7 @@ class Directory extends FileAbstract implements DirectoryInterface * {@inheritdoc} */ public static function count(string $path, bool $recursive = true, array $ignore = ['.', '..', 'cgi-bin', - '.DS_Store']) + '.DS_Store']) : int { $size = 0; $files = scandir($path); @@ -217,7 +217,7 @@ class Directory extends FileAbstract implements DirectoryInterface /** * {@inheritdoc} */ - public static function permission(string $path) : int + public static function permission(string $path) : string { // TODO: Implement permission() method. } @@ -246,6 +246,14 @@ class Directory extends FileAbstract implements DirectoryInterface return file_exists($path); } + /** + * {@inheritdoc} + */ + public static function sanitize(string $path) : string + { + return preg_replace('[^\w\s\d\.\-_~,;:\[\]\(\]\/]', '', $path); + } + /** * {@inheritdoc} */ diff --git a/System/File/Local/File.php b/System/File/Local/File.php index 6b9b893f2..38a3737bf 100644 --- a/System/File/Local/File.php +++ b/System/File/Local/File.php @@ -14,6 +14,7 @@ * @link http://orange-management.com */ namespace phpOMS\System\File\Local; + use phpOMS\System\File\ContainerInterface; use phpOMS\System\File\ContentPutMode; use phpOMS\System\File\FileInterface; @@ -139,6 +140,14 @@ class File extends FileAbstract implements FileInterface return Directory::parent(dirname($path)); } + /** + * {@inheritdoc} + */ + public static function sanitize(string $path) : string + { + return preg_replace('[^\w\s\d\.\-_~,;:\[\]\(\]]', '', $path); + } + /** * {@inheritdoc} */ @@ -196,7 +205,7 @@ class File extends FileAbstract implements FileInterface /** * {@inheritdoc} */ - public static function permission(string $path) : int + public static function permission(string $path) : string { if (!file_exists($path)) { throw new PathException($path);