diff --git a/System/File/ContainerInterface.php b/System/File/ContainerInterface.php index a34f009ce..4bfbc08cc 100644 --- a/System/File/ContainerInterface.php +++ b/System/File/ContainerInterface.php @@ -193,21 +193,6 @@ interface ContainerInterface */ public static function basename(string $path) : string; - /** - * Get amount of sub-resources. - * - * A file will always return 1 as it doesn't have any sub-resources. - * - * @param string $path Path of the resource - * @param bool $recursive Should count also sub-sub-resources - * - * @return int - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public static function count(string $path, bool $recursive = false) : int; - /** * Get amount of sub-resources. * diff --git a/System/File/DirectoryInterface.php b/System/File/DirectoryInterface.php index ba4c9e7e7..09f5c21a7 100644 --- a/System/File/DirectoryInterface.php +++ b/System/File/DirectoryInterface.php @@ -30,4 +30,43 @@ namespace phpOMS\System\File; */ interface DirectoryInterface extends ContainerInterface, \Iterator, \ArrayAccess { + /** + * Get amount of sub-resources. + * + * A file will always return 1 as it doesn't have any sub-resources. + * + * @param string $path Path of the resource + * @param bool $recursive Should count also sub-sub-resources + * @param array $ignore Ignore files + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function count(string $path, bool $recursive = false, array $ignore = []) : int; + + /** + * Get node by name. + * + * @param string $name File/direcotry name + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getNode(string $name); + + /** + * Add file or directory. + * + * @param mixed $file File to add + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function add($file) : bool; } diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index ba1f6d5dc..7a07e61ca 100644 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -87,16 +87,9 @@ class Directory extends FileAbstract implements DirectoryInterface } /** - * Add file or directory. - * - * @param FileAbstract $file File to add - * - * @return bool - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ - public function add(FileAbstract $file) : bool + public function add($file) : bool { $this->count += $file->getCount(); $this->size += $file->getSize(); @@ -106,19 +99,9 @@ class Directory extends FileAbstract implements DirectoryInterface } /** - * Get folder size recursively. - * - * This can become rather slow for large structures. - * - * @param string $dir Root dir to inspect - * @param bool $recursive Get size recursive - * - * @return int - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ - public static function getFolderSize(string $dir, bool $recursive = true) : int + public static function size(string $dir, bool $recursive = true) : int { $countSize = 0; $count = 0; @@ -129,7 +112,7 @@ class Directory extends FileAbstract implements DirectoryInterface foreach ($dir_array as $key => $filename) { if ($filename != ".." && $filename != ".") { if (is_dir($dir . "/" . $filename) && $recursive) { - $countSize += self::getFolderSize($dir . "/" . $filename, $recursive); + $countSize += self::size($dir . "/" . $filename, $recursive); } else { if (is_file($dir . "/" . $filename)) { $countSize += filesize($dir . "/" . $filename); @@ -144,18 +127,9 @@ class Directory extends FileAbstract implements DirectoryInterface } /** - * Get file count inside path. - * - * @param string $path Path to folder - * @param bool $recursive Should sub folders be counted as well? - * @param array $ignore Ignore these sub-paths - * - * @return int - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ - public static function getFileCount(string $path, bool $recursive = true, array $ignore = ['.', '..', 'cgi-bin', + public static function count(string $path, bool $recursive = true, array $ignore = ['.', '..', 'cgi-bin', '.DS_Store']) { $size = 0; @@ -167,7 +141,7 @@ class Directory extends FileAbstract implements DirectoryInterface } if (is_dir(rtrim($path, '/') . '/' . $t)) { if ($recursive) { - $size += self::getFileCount(rtrim($path, '/') . '/' . $t, true, $ignore); + $size += self::count(rtrim($path, '/') . '/' . $t, true, $ignore); } } else { $size++; @@ -264,14 +238,6 @@ class Directory extends FileAbstract implements DirectoryInterface // TODO: Implement move() method. } - /** - * {@inheritdoc} - */ - public static function size(string $path, bool $recursive = true) : int - { - // TODO: Implement size() method. - } - /** * {@inheritdoc} */ @@ -281,14 +247,7 @@ class Directory extends FileAbstract implements DirectoryInterface } /** - * Get node by name. - * - * @param string $name File/direcotry name - * - * @return FileAbstract - * - * @since 1.0.0 - * @author Dennis Eichhorn + * {@inheritdoc} */ public function getNode(string $name) : FileAbstract { @@ -424,14 +383,6 @@ class Directory extends FileAbstract implements DirectoryInterface // TODO: Implement basename() method. } - /** - * {@inheritdoc} - */ - public static function count(string $path, bool $recursive = false) : int - { - // TODO: Implement count() method. - } - /** * {@inheritdoc} */ diff --git a/System/File/Local/File.php b/System/File/Local/File.php index 0e1265154..3e4fb4a31 100644 --- a/System/File/Local/File.php +++ b/System/File/Local/File.php @@ -420,14 +420,6 @@ class File extends FileAbstract implements FileInterface // TODO: Implement basename() method. } - /** - * {@inheritdoc} - */ - public static function count(string $path, bool $recursive = false) : int - { - // TODO: Implement count() method. - } - /** * {@inheritdoc} */