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