From 00a09284efa406c1f704a5a22048eeffe3f28505 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 9 Dec 2014 12:28:23 +0100 Subject: [PATCH] lib: Add NonEmptyFileIterator Add iterator for iterating over non-empty files. --- library/Icinga/File/NonEmptyFileIterator.php | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 library/Icinga/File/NonEmptyFileIterator.php diff --git a/library/Icinga/File/NonEmptyFileIterator.php b/library/Icinga/File/NonEmptyFileIterator.php new file mode 100644 index 000000000..c5c7fda45 --- /dev/null +++ b/library/Icinga/File/NonEmptyFileIterator.php @@ -0,0 +1,49 @@ + + * + */ +class NonEmptyFileIterator extends FilterIterator +{ + /** + * Accept non-empty files + * + * @return bool Whether the current element of the iterator is acceptable + * through this filter + */ + public function accept() + { + $current = $this->current(); + /** @type $current \SplFileInfo */ + if (! $current->isFile() + || $current->getSize() === 0 + ) { + return false; + } + return true; + } +}