Skip to content

Instantly share code, notes, and snippets.

@cam-gists
Created July 2, 2012 21:41
Show Gist options
  • Select an option

  • Save cam-gists/3035886 to your computer and use it in GitHub Desktop.

Select an option

Save cam-gists/3035886 to your computer and use it in GitHub Desktop.
PHP: File Extension Filter
<?php
class FileExtensionFilter extends FilterIterator
{
// whitelist of file extensions
protected $ext = ["php", "txt"];
// an abstract method which must be implemented in subclass
public function accept() {
return in_array($this->getExtension(), $this->ext);
}
}
//create a new iterator
$dir = new FileExtensionFilter(new DirectoryIterator("./"));
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment