|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Erelke\TwigSpreadsheetBundle\Helper; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Filesystem\Exception\IOException; |
|
6
|
|
|
use Symfony\Component\Filesystem\Filesystem as BaseFilesystem; |
|
7
|
|
|
use Traversable; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class Filesystem. |
|
11
|
|
|
*/ |
|
12
|
|
|
class Filesystem |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var BaseFilesystem |
|
16
|
|
|
*/ |
|
17
|
|
|
private static $delegate; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Creates a directory recursively. |
|
21
|
|
|
* |
|
22
|
|
|
* @param string|array|Traversable $dirs The directory path |
|
23
|
|
|
* @param int $mode The directory mode |
|
24
|
|
|
* |
|
25
|
|
|
* @throws IOException On any directory creation failure |
|
26
|
|
|
*/ |
|
27
|
|
|
public static function mkdir($dirs, int $mode = 0777) |
|
28
|
|
|
{ |
|
29
|
|
|
self::getDelegate()->mkdir($dirs, $mode); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Checks the existence of files or directories. |
|
34
|
|
|
* |
|
35
|
|
|
* @param string|array|Traversable $files A filename, an array of files, or a Traversable instance to check |
|
36
|
|
|
* |
|
37
|
|
|
* @return bool true if the file exists, false otherwise |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function exists($files): bool |
|
40
|
|
|
{ |
|
41
|
|
|
return self::getDelegate()->exists($files); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Removes files or directories. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string|array|Traversable $files A filename, an array of files, or a \Traversable instance to remove |
|
48
|
|
|
* |
|
49
|
|
|
* @throws IOException When removal fails |
|
50
|
|
|
*/ |
|
51
|
|
|
public static function remove($files) |
|
52
|
|
|
{ |
|
53
|
|
|
self::getDelegate()->remove($files); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Atomically dumps content into a file. |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $filename The file to be written to |
|
60
|
|
|
* @param string $content The data to write into the file |
|
61
|
|
|
* |
|
62
|
|
|
* @throws IOException If the file cannot be written to |
|
63
|
|
|
*/ |
|
64
|
|
|
public static function dumpFile(string $filename, string $content) |
|
65
|
|
|
{ |
|
66
|
|
|
self::getDelegate()->dumpFile($filename, $content); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return BaseFilesystem |
|
71
|
|
|
*/ |
|
72
|
|
|
public static function getDelegate(): BaseFilesystem |
|
73
|
|
|
{ |
|
74
|
|
|
if (!self::$delegate) { |
|
75
|
|
|
self::$delegate = new BaseFilesystem(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return self::$delegate; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|