1 | <?php |
||
10 | class ReadDirectory |
||
11 | { |
||
12 | /** |
||
13 | * @const ERR_RUN_OPENDIR Exception code if opendir fail |
||
14 | */ |
||
15 | const ERR_RUN_OPENDIR = 1206001; |
||
16 | |||
17 | /** |
||
18 | * @var string $calledClass : Name of the current class. |
||
19 | * For recall the correct class when she's extended. |
||
20 | */ |
||
21 | protected $calledClass = ''; |
||
22 | |||
23 | /** |
||
24 | * @var array $list : List all path found |
||
25 | */ |
||
26 | protected $list; |
||
27 | |||
28 | /** |
||
29 | * @var array $ignore : Item to ignore during the reading of directories |
||
30 | */ |
||
31 | protected $ignore = ['.', '..']; |
||
32 | |||
33 | /* |
||
34 | * Constructeur |
||
35 | * |
||
36 | * @param array &$listFiles : List of file(s) found |
||
37 | */ |
||
38 | public function __construct(&$listFiles) |
||
43 | |||
44 | /** |
||
45 | * Getter accessor to the property calledClass |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | public function getCalledClass() |
||
53 | |||
54 | /** |
||
55 | * Getter accessor to the property list |
||
56 | * |
||
57 | * @return array |
||
58 | */ |
||
59 | public function getList() |
||
63 | |||
64 | /** |
||
65 | * Getter accessor to the property ignore |
||
66 | * |
||
67 | * @return array |
||
68 | */ |
||
69 | public function getIgnore() |
||
73 | |||
74 | /** |
||
75 | * Read all the directories |
||
76 | * |
||
77 | * @param string $path : Path to read |
||
78 | * |
||
79 | * @return void |
||
80 | */ |
||
81 | public function run($path) |
||
111 | |||
112 | /** |
||
113 | * Action to do when an item (file or directory) is found. |
||
114 | * |
||
115 | * @param string $fileName The file's name |
||
116 | * @param string $pathToFile The file's path |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | protected function itemAction($fileName, $pathToFile) |
||
121 | { |
||
122 | if (in_array($fileName, $this->ignore)) { |
||
123 | return 'continue'; |
||
124 | } |
||
125 | |||
126 | return ''; |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Recall ReadDirectory to read this directory |
||
131 | * This is to avoid having the recursion error |
||
132 | * |
||
133 | * @param string $dirPath |
||
134 | */ |
||
135 | protected function dirAction($dirPath) |
||
140 | } |
||
141 |