mirror of
				https://github.com/Icinga/icingaweb2.git
				synced 2025-11-04 05:05:01 +01:00 
			
		
		
		
	Becasue of too many kittens PSR-5 backed off of deprecating @var. So that's the way we go too.
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
 | 
						|
 | 
						|
namespace Icinga\File;
 | 
						|
 | 
						|
use FilterIterator;
 | 
						|
 | 
						|
/**
 | 
						|
 * Iterator over non-empty files
 | 
						|
 *
 | 
						|
 * Usage example:
 | 
						|
 * <code>
 | 
						|
 * <?php
 | 
						|
 *
 | 
						|
 * namespace Icinga\Example;
 | 
						|
 *
 | 
						|
 * use RecursiveDirectoryIterator;
 | 
						|
 * use RecursiveIteratorIterator;
 | 
						|
 * use Icinga\File\NonEmptyFilterIterator;
 | 
						|
 *
 | 
						|
 * $nonEmptyFiles = new NonEmptyFileIterator(
 | 
						|
 *     new RecursiveIteratorIterator(
 | 
						|
 *         new RecursiveDirectoryIterator(__DIR__),
 | 
						|
 *         RecursiveIteratorIterator::SELF_FIRST
 | 
						|
 *     )
 | 
						|
 * );
 | 
						|
 * </code>
 | 
						|
 */
 | 
						|
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();
 | 
						|
        /** @var $current \SplFileInfo */
 | 
						|
        if (! $current->isFile()
 | 
						|
            || $current->getSize() === 0
 | 
						|
        ) {
 | 
						|
            return false;
 | 
						|
        }
 | 
						|
        return true;
 | 
						|
    }
 | 
						|
}
 |