11
11
12
12
namespace Symfony \Component \Filesystem ;
13
13
14
+ use Symfony \Component \Filesystem \Exception \IOException ;
15
+
14
16
/**
15
17
* Provides basic utility to manipulate the file system.
16
18
*
@@ -29,7 +31,7 @@ class Filesystem
29
31
* @param string $targetFile The target filename
30
32
* @param array $override Whether to override an existing file or not
31
33
*
32
- * @throws Exception\ IOException When copy fails
34
+ * @throws IOException When copy fails
33
35
*/
34
36
public function copy ($ originFile , $ targetFile , $ override = false )
35
37
{
@@ -43,7 +45,7 @@ public function copy($originFile, $targetFile, $override = false)
43
45
44
46
if ($ doCopy ) {
45
47
if (true !== @copy ($ originFile , $ targetFile )) {
46
- throw new Exception \ IOException (sprintf ('Failed to copy %s to %s ' , $ originFile , $ targetFile ));
48
+ throw new IOException (sprintf ('Failed to copy %s to %s ' , $ originFile , $ targetFile ));
47
49
}
48
50
}
49
51
}
@@ -54,7 +56,7 @@ public function copy($originFile, $targetFile, $override = false)
54
56
* @param string|array|\Traversable $dirs The directory path
55
57
* @param integer $mode The directory mode
56
58
*
57
- * @throws Exception\ IOException On any directory creation failure
59
+ * @throws IOException On any directory creation failure
58
60
*/
59
61
public function mkdir ($ dirs , $ mode = 0777 )
60
62
{
@@ -64,7 +66,7 @@ public function mkdir($dirs, $mode = 0777)
64
66
}
65
67
66
68
if (true !== @mkdir ($ dir , $ mode , true )) {
67
- throw new Exception \ IOException (sprintf ('Failed to create %s ' , $ dir ));
69
+ throw new IOException (sprintf ('Failed to create %s ' , $ dir ));
68
70
}
69
71
}
70
72
}
@@ -94,7 +96,7 @@ public function exists($files)
94
96
* @param integer $time The touch time as a unix timestamp
95
97
* @param integer $atime The access time as a unix timestamp
96
98
*
97
- * @throws Exception\ IOException When touch fails
99
+ * @throws IOException When touch fails
98
100
*/
99
101
public function touch ($ files , $ time = null , $ atime = null )
100
102
{
@@ -104,7 +106,7 @@ public function touch($files, $time = null, $atime = null)
104
106
105
107
foreach ($ this ->toIterator ($ files ) as $ file ) {
106
108
if (true !== @touch ($ file , $ time , $ atime )) {
107
- throw new Exception \ IOException (sprintf ('Failed to touch %s ' , $ file ));
109
+ throw new IOException (sprintf ('Failed to touch %s ' , $ file ));
108
110
}
109
111
}
110
112
}
@@ -114,7 +116,7 @@ public function touch($files, $time = null, $atime = null)
114
116
*
115
117
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to remove
116
118
*
117
- * @throws Exception\ IOException When removal fails
119
+ * @throws IOException When removal fails
118
120
*/
119
121
public function remove ($ files )
120
122
{
@@ -129,17 +131,17 @@ public function remove($files)
129
131
$ this ->remove (new \FilesystemIterator ($ file ));
130
132
131
133
if (true !== @rmdir ($ file )) {
132
- throw new Exception \ IOException (sprintf ('Failed to remove directory %s ' , $ file ));
134
+ throw new IOException (sprintf ('Failed to remove directory %s ' , $ file ));
133
135
}
134
136
} else {
135
137
// https://bugs.php.net/bug.php?id=52176
136
138
if (defined ('PHP_WINDOWS_VERSION_MAJOR ' ) && is_dir ($ file )) {
137
139
if (true !== @rmdir ($ file )) {
138
- throw new Exception \ IOException (sprintf ('Failed to remove file %s ' , $ file ));
140
+ throw new IOException (sprintf ('Failed to remove file %s ' , $ file ));
139
141
}
140
142
} else {
141
143
if (true !== @unlink ($ file )) {
142
- throw new Exception \ IOException (sprintf ('Failed to remove file %s ' , $ file ));
144
+ throw new IOException (sprintf ('Failed to remove file %s ' , $ file ));
143
145
}
144
146
}
145
147
}
@@ -154,7 +156,7 @@ public function remove($files)
154
156
* @param integer $umask The mode mask (octal)
155
157
* @param Boolean $recursive Whether change the mod recursively or not
156
158
*
157
- * @throws Exception\ IOException When the change fail
159
+ * @throws IOException When the change fail
158
160
*/
159
161
public function chmod ($ files , $ mode , $ umask = 0000 , $ recursive = false )
160
162
{
@@ -163,7 +165,7 @@ public function chmod($files, $mode, $umask = 0000, $recursive = false)
163
165
$ this ->chmod (new \FilesystemIterator ($ file ), $ mode , $ umask , true );
164
166
}
165
167
if (true !== @chmod ($ file , $ mode & ~$ umask )) {
166
- throw new Exception \ IOException (sprintf ('Failed to chmod file %s ' , $ file ));
168
+ throw new IOException (sprintf ('Failed to chmod file %s ' , $ file ));
167
169
}
168
170
}
169
171
}
@@ -175,7 +177,7 @@ public function chmod($files, $mode, $umask = 0000, $recursive = false)
175
177
* @param string $user The new owner user name
176
178
* @param Boolean $recursive Whether change the owner recursively or not
177
179
*
178
- * @throws Exception\ IOException When the change fail
180
+ * @throws IOException When the change fail
179
181
*/
180
182
public function chown ($ files , $ user , $ recursive = false )
181
183
{
@@ -185,11 +187,11 @@ public function chown($files, $user, $recursive = false)
185
187
}
186
188
if (is_link ($ file ) && function_exists ('lchown ' )) {
187
189
if (true !== @lchown ($ file , $ user )) {
188
- throw new Exception \ IOException (sprintf ('Failed to chown file %s ' , $ file ));
190
+ throw new IOException (sprintf ('Failed to chown file %s ' , $ file ));
189
191
}
190
192
} else {
191
193
if (true !== @chown ($ file , $ user )) {
192
- throw new Exception \ IOException (sprintf ('Failed to chown file %s ' , $ file ));
194
+ throw new IOException (sprintf ('Failed to chown file %s ' , $ file ));
193
195
}
194
196
}
195
197
}
@@ -202,7 +204,7 @@ public function chown($files, $user, $recursive = false)
202
204
* @param string $group The group name
203
205
* @param Boolean $recursive Whether change the group recursively or not
204
206
*
205
- * @throws Exception\ IOException When the change fail
207
+ * @throws IOException When the change fail
206
208
*/
207
209
public function chgrp ($ files , $ group , $ recursive = false )
208
210
{
@@ -212,11 +214,11 @@ public function chgrp($files, $group, $recursive = false)
212
214
}
213
215
if (is_link ($ file ) && function_exists ('lchgrp ' )) {
214
216
if (true !== @lchgrp ($ file , $ group )) {
215
- throw new Exception \ IOException (sprintf ('Failed to chgrp file %s ' , $ file ));
217
+ throw new IOException (sprintf ('Failed to chgrp file %s ' , $ file ));
216
218
}
217
219
} else {
218
220
if (true !== @chgrp ($ file , $ group )) {
219
- throw new Exception \ IOException (sprintf ('Failed to chgrp file %s ' , $ file ));
221
+ throw new IOException (sprintf ('Failed to chgrp file %s ' , $ file ));
220
222
}
221
223
}
222
224
}
@@ -228,18 +230,18 @@ public function chgrp($files, $group, $recursive = false)
228
230
* @param string $origin The origin filename
229
231
* @param string $target The new filename
230
232
*
231
- * @throws Exception\ IOException When target file already exists
232
- * @throws Exception\ IOException When origin cannot be renamed
233
+ * @throws IOException When target file already exists
234
+ * @throws IOException When origin cannot be renamed
233
235
*/
234
236
public function rename ($ origin , $ target )
235
237
{
236
238
// we check that target does not exist
237
239
if (is_readable ($ target )) {
238
- throw new Exception \ IOException (sprintf ('Cannot rename because the target "%s" already exist. ' , $ target ));
240
+ throw new IOException (sprintf ('Cannot rename because the target "%s" already exist. ' , $ target ));
239
241
}
240
242
241
243
if (true !== @rename ($ origin , $ target )) {
242
- throw new Exception \ IOException (sprintf ('Cannot rename "%s" to "%s". ' , $ origin , $ target ));
244
+ throw new IOException (sprintf ('Cannot rename "%s" to "%s". ' , $ origin , $ target ));
243
245
}
244
246
}
245
247
@@ -250,7 +252,7 @@ public function rename($origin, $target)
250
252
* @param string $targetDir The symbolic link name
251
253
* @param Boolean $copyOnWindows Whether to copy files if on Windows
252
254
*
253
- * @throws Exception\ IOException When symlink fails
255
+ * @throws IOException When symlink fails
254
256
*/
255
257
public function symlink ($ originDir , $ targetDir , $ copyOnWindows = false )
256
258
{
@@ -273,7 +275,7 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
273
275
274
276
if (!$ ok ) {
275
277
if (true !== @symlink ($ originDir , $ targetDir )) {
276
- throw new Exception \ IOException (sprintf ('Failed to create symbolic link from %s to %s ' , $ originDir , $ targetDir ));
278
+ throw new IOException (sprintf ('Failed to create symbolic link from %s to %s ' , $ originDir , $ targetDir ));
277
279
}
278
280
}
279
281
}
@@ -322,7 +324,7 @@ public function makePathRelative($endPath, $startPath)
322
324
* - $options['override'] Whether to override an existing file on copy or not (see copy())
323
325
* - $options['copy_on_windows'] Whether to copy files instead of links on Windows (see symlink())
324
326
*
325
- * @throws Exception\ IOException When file type is unknown
327
+ * @throws IOException When file type is unknown
326
328
*/
327
329
public function mirror ($ originDir , $ targetDir , \Traversable $ iterator = null , $ options = array ())
328
330
{
@@ -349,7 +351,7 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
349
351
} elseif (is_file ($ file ) || ($ copyOnWindows && is_link ($ file ))) {
350
352
$ this ->copy ($ file , $ target , isset ($ options ['override ' ]) ? $ options ['override ' ] : false );
351
353
} else {
352
- throw new Exception \ IOException (sprintf ('Unable to guess "%s" file type. ' , $ file ));
354
+ throw new IOException (sprintf ('Unable to guess "%s" file type. ' , $ file ));
353
355
}
354
356
}
355
357
}
0 commit comments