|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PHP\Wrappers; |
|
4
|
|
|
|
|
5
|
|
|
use Directory; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class Dir |
|
9
|
|
|
* |
|
10
|
|
|
* @package PHP\Wrappers |
|
11
|
|
|
* @author Aurimas Niekis <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class Dir |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Change directory |
|
17
|
|
|
* |
|
18
|
|
|
* @param string $directory The new current directory |
|
19
|
|
|
* |
|
20
|
|
|
* @return bool |
|
21
|
|
|
*/ |
|
22
|
|
|
public function chDir(string $directory) : bool |
|
23
|
|
|
{ |
|
24
|
|
|
return chdir($directory); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Change the root directory |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $directory The path to change the root directory to. |
|
31
|
|
|
* |
|
32
|
|
|
* @return bool |
|
33
|
|
|
*/ |
|
34
|
|
|
public function chroot(string $directory) : bool |
|
35
|
|
|
{ |
|
36
|
|
|
return chroot($directory); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Close directory handle |
|
41
|
|
|
* |
|
42
|
|
|
* @param resource $dirHandle The directory handle resource previously opened |
|
43
|
|
|
* with opendir. If the directory handle is |
|
44
|
|
|
* not specified, the last link opened by opendir |
|
45
|
|
|
* is assumed. |
|
46
|
|
|
* |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
|
|
public function closeDir($dirHandle = null) |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
call_user_func_array('closedir', func_get_args()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Return an instance of the Directory class |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $directory |
|
58
|
|
|
* @param resource $context |
|
59
|
|
|
* |
|
60
|
|
|
* @return Directory |
|
61
|
|
|
*/ |
|
62
|
|
|
public function dir(string $directory, $context = null) : Directory |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
return call_user_func_array('dir', func_get_args()); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Gets the current working directory |
|
69
|
|
|
* |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getcwd() : string |
|
73
|
|
|
{ |
|
74
|
|
|
return getcwd(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Open directory handle |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $path The directory path that is to be opened |
|
81
|
|
|
* @param resource $context For a description of the context parameter, |
|
82
|
|
|
* refer to the streams section of |
|
83
|
|
|
* the manual. |
|
84
|
|
|
* |
|
85
|
|
|
* @return resource |
|
86
|
|
|
*/ |
|
87
|
|
|
public function openDir(string $path, $context = null) |
|
|
|
|
|
|
88
|
|
|
{ |
|
89
|
|
|
return call_user_func_array('opendir', func_get_args()); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Read entry from directory handle |
|
94
|
|
|
* |
|
95
|
|
|
* @param resource $dirHandle The directory handle resource previously opened |
|
96
|
|
|
* with opendir. If the directory handle is |
|
97
|
|
|
* not specified, the last link opened by opendir |
|
98
|
|
|
* is assumed. |
|
99
|
|
|
* |
|
100
|
|
|
* @return string |
|
101
|
|
|
*/ |
|
102
|
|
|
public function readdDr($dirHandle = null) : string |
|
|
|
|
|
|
103
|
|
|
{ |
|
104
|
|
|
return call_user_func_array('readdir', func_get_args()); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Rewind directory handle |
|
109
|
|
|
* |
|
110
|
|
|
* @param resource $dirHandle The directory handle resource previously opened |
|
111
|
|
|
* with opendir. If the directory handle is |
|
112
|
|
|
* not specified, the last link opened by opendir |
|
113
|
|
|
* is assumed. |
|
114
|
|
|
* |
|
115
|
|
|
* @return void |
|
116
|
|
|
*/ |
|
117
|
|
|
public function rewindDir($dirHandle = null) |
|
|
|
|
|
|
118
|
|
|
{ |
|
119
|
|
|
call_user_func_array('rewinddir', func_get_args()); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* List files and directories inside the specified path |
|
124
|
|
|
* |
|
125
|
|
|
* @param string $directory The directory that will be scanned. |
|
126
|
|
|
* @param int $sortingOrder By default, the sorted order is alphabetical in ascending order. If |
|
127
|
|
|
* the optional sorting_order is set to |
|
128
|
|
|
* SCANDIR_SORT_DESCENDING, then the sort order is |
|
129
|
|
|
* alphabetical in descending order. If it is set to |
|
130
|
|
|
* SCANDIR_SORT_NONE then the result is unsorted. |
|
131
|
|
|
* @param resource $context For a description of the context parameter, |
|
132
|
|
|
* refer to the streams section of |
|
133
|
|
|
* the manual. |
|
134
|
|
|
* |
|
135
|
|
|
* @return array |
|
136
|
|
|
*/ |
|
137
|
|
|
public function scanDir(string $directory, int $sortingOrder = null, $context = null) : array |
|
|
|
|
|
|
138
|
|
|
{ |
|
139
|
|
|
return call_user_func_array('scandir', func_get_args()); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.