From 040d655ab3813d70026721fa6265bf906871d928 Mon Sep 17 00:00:00 2001 From: Laurent Marquet Date: Mon, 13 Feb 2017 12:40:13 +0100 Subject: [PATCH] Add isFile function I think we need to have a difference between file_exists and is_file --- Filesystem.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Filesystem.php b/Filesystem.php index b93e01db6f..c0569412db 100644 --- a/Filesystem.php +++ b/Filesystem.php @@ -127,6 +127,28 @@ public function exists($files) return true; } + + /** + * Checks if files are real files. + * + * @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to check + * + * @return bool true if the file is a real file, false otherwise + */ + public function isFile($files) + { + foreach ($this->toIterator($files) as $file) { + if ('\\' === DIRECTORY_SEPARATOR && strlen($file) > 258) { + throw new IOException('Could not check if file exist because path length exceeds 258 characters.', 0, null, $file); + } + if (!is_file($file)) { + return false; + } + } + return true; + } + + /** * Sets access and modification time of file. *