Created
June 3, 2011 08:12
-
-
Save maartenJacobs/1006042 to your computer and use it in GitHub Desktop.
Simple File filtering in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IncExtFilterIterator extends FilterIterator | |
{ | |
protected $_extensions; | |
public function __construct($path, $includeExt) | |
{ | |
parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); | |
$this->_extensions = $includeExt; | |
} | |
public function accept() | |
{ | |
$item = $this->getInnerIterator(); | |
$filename = $item->getFileName(); | |
if ($item->isFile() && in_array(pathinfo($filename, PATHINFO_EXTENSION), $this->_extensions)) { | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment