|
1 | 1 | <?php |
2 | 2 | function subFolder( $_dir = "./" ) { |
3 | | - $temp = array(); |
4 | | - if (is_dir($_dir)) { |
5 | | - if ($dirOpened = opendir($_dir)) { |
6 | | - while (($file = readdir($dirOpened)) !== false) { |
7 | | - if( ($file !='.')&&($file !='..') ) { |
8 | | - array_push($temp,$file); |
9 | | - } |
10 | | - } |
11 | | - closedir($dirOpened); |
12 | | - } |
13 | | - } |
| 3 | + $temp = fetchInSubFolder($_dir, function( $_file ) { |
| 4 | + return true; |
| 5 | + }); |
14 | 6 | return $temp; |
15 | 7 | } |
16 | 8 | function subFolder_file( $_dir = "./" ) { |
17 | | - $temp = array(); |
18 | | - if (is_dir($_dir)) { |
19 | | - if ($dirOpened = opendir($_dir)) { |
20 | | - while (($file = readdir($dirOpened)) !== false) { |
21 | | - if( ($file !='.') && ($file !='..') && !is_dir($file) ) { |
22 | | - array_push($temp,$file); |
23 | | - } |
24 | | - } |
25 | | - closedir($dirOpened); |
26 | | - } |
27 | | - } |
| 9 | + $temp = fetchInSubFolder($_dir, function( $_file ) { |
| 10 | + return !is_dir($_file); |
| 11 | + }); |
28 | 12 | return $temp; |
29 | 13 | } |
30 | 14 | function subFolder_dir( $_dir = "./" ) { |
| 15 | + $temp = fetchInSubFolder($_dir, function( $_file ) { |
| 16 | + return !is_file($_file); |
| 17 | + }); |
| 18 | + return $temp; |
| 19 | + } |
| 20 | + function fetchInSubFolder( $_dir = "./", $_function) { |
31 | 21 | $temp = array(); |
32 | 22 | if (is_dir($_dir)) { |
33 | 23 | if ($dirOpened = opendir($_dir)) { |
34 | | - while (($file = readdir($dirOpened)) !== false) { |
35 | | - if( ($file !='.') && ($file !='..') && !is_file($file) ) { |
36 | | - array_push($temp,$file); |
37 | | - } |
38 | | - } |
| 24 | + while (($file = readdir($dirOpened)) !== false) |
| 25 | + if( ($file !='.')&&($file !='..') ) |
| 26 | + if($_function($file)) |
| 27 | + array_push($temp,$file); |
39 | 28 | closedir($dirOpened); |
40 | 29 | } |
41 | 30 | } |
42 | 31 | return $temp; |
43 | 32 | } |
44 | 33 | function require_subfolder( $_dir = "./" ) { |
45 | 34 | $temp = subFolder_file($_dir); |
46 | | - foreach ($temp as $i) { |
| 35 | + foreach ($temp as $i) |
47 | 36 | require_once($_dir."/".$i); |
48 | | - } |
49 | 37 | } |
50 | 38 | function require_js( $_dir = "./" ) { |
51 | 39 | $tempArray = array(); |
52 | 40 | $temp = subFolder_file($_dir); |
53 | | - foreach ($temp as $i) { |
| 41 | + foreach ($temp as $i) |
54 | 42 | array_push($tempArray, $_dir."/".$i); |
55 | | - } |
56 | 43 | return $tempArray; |
57 | 44 | } |
58 | 45 | ?> |
0 commit comments