1: <?php
2: /**
3: * Pry Framework
4: *
5: * LICENSE
6: *
7: * This source file is subject to the new BSD license that is bundled
8: * with this package in the file LICENSE.txt.
9: *
10: * @version $Revision: 171 $
11: */
12:
13: /**
14: * Decorator permettant de filtrer les éléments listés
15: * @category Pry
16: * @package File
17: * @subpackage File_Decorator
18: * @version 1.0.0
19: * @author Olivier ROGER <oroger.fr>
20: */
21: class File_Decorator_Filter extends FilterIterator
22: {
23: /**
24: * Liste des extensions à autoriser. Toutes si vide
25: * @var array
26: */
27: private $extensions = array();
28:
29: /**
30: * Vérifie qu'un élément peut être listé
31: * @return boolean
32: */
33: public function accept()
34: {
35: if(empty($this->extensions))
36: return true;
37: else
38: {
39: if(in_array(File_Util::getExtension($this->current()), $this->extensions))
40: return true;
41: }
42: return false;
43: }
44:
45: /**
46: * Défini une ou plusieurs extsions à autoriser
47: * @param string|array $filter
48: */
49: public function setExtension($filter)
50: {
51: if(!is_array($filter))
52: $this->extensions[] = strtolower($filter);
53: else
54: $this->extensions = array_merge($this->extensions,$filter);
55: }
56: }
57: ?>
58: