1 | <?php |
||
19 | class Filesystem extends \Symfony\Component\Filesystem\Filesystem |
||
20 | { |
||
21 | /** |
||
22 | * Build an absolute file or directory path separated by the OS specific directory separator. |
||
23 | * |
||
24 | * @param string ...$pathFragments |
||
25 | * |
||
26 | * @return string |
||
27 | */ |
||
28 | 80 | public function absolutePath($pathFragments) |
|
29 | { |
||
30 | 80 | if ($this->isAbsolutePath($pathFragments)) |
|
31 | { |
||
32 | 53 | return $pathFragments; |
|
33 | } |
||
34 | |||
35 | 60 | $args = func_get_args(); |
|
36 | 60 | array_unshift($args, getcwd()); |
|
37 | |||
38 | 60 | return implode(DIRECTORY_SEPARATOR, $args); |
|
39 | } |
||
40 | |||
41 | /** |
||
42 | * Build a file or directory path separated by the OS specific directory separator. |
||
43 | * |
||
44 | * @param string ...$pathFragments |
||
45 | * |
||
46 | * @return string |
||
47 | */ |
||
48 | 49 | public function appendPath($pathFragments) |
|
52 | |||
53 | /** |
||
54 | * Copy a file or folder recursively. |
||
55 | * |
||
56 | * @param string $originFile The original filename |
||
57 | * @param string $targetFile The target filename |
||
58 | * @param bool $overwriteNewerFiles If true, target files newer than origin files are overwritten |
||
59 | * |
||
60 | * @throws FileNotFoundException When originFile doesn't exist |
||
61 | * @throws IOException When copy fails |
||
62 | */ |
||
63 | public function copy($originFile, $targetFile, $overwriteNewerFiles = false) |
||
64 | { |
||
65 | if ($this->isDir($originFile)) |
||
66 | { |
||
67 | if (!$this->isDir($targetFile)) |
||
68 | { |
||
69 | mkdir($targetFile, 0755, true); |
||
70 | } |
||
71 | |||
72 | $dir = dir($originFile); |
||
73 | |||
74 | while (false !== $entry = $dir->read()) |
||
75 | { |
||
76 | // Skip pointers |
||
77 | if ($entry == '.' || $entry == '..') |
||
78 | { |
||
79 | continue; |
||
80 | } |
||
81 | |||
82 | $this->copy("$originFile/$entry", "$targetFile/$entry", true); |
||
3 ignored issues
–
show
|
|||
83 | } |
||
84 | |||
85 | $dir->close(); |
||
86 | } |
||
87 | else |
||
88 | { |
||
89 | parent::copy($originFile, $targetFile, $overwriteNewerFiles); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Create an instance of Symfony's SplFileInfo with relative path information. |
||
95 | * |
||
96 | * @param string $filePath |
||
97 | * |
||
98 | * @return SplFileInfo |
||
99 | */ |
||
100 | public function createSplFileInfo($filePath) |
||
101 | { |
||
102 | return new SplFileInfo( |
||
103 | $this->absolutePath($filePath), |
||
104 | $this->getRelativePath($this->getFolderPath($filePath)), |
||
105 | $this->getRelativePath($filePath) |
||
106 | ); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Strip the current working directory from an absolute path. |
||
111 | * |
||
112 | * @param string $path An absolute path |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | 79 | public function getRelativePath($path) |
|
120 | |||
121 | /** |
||
122 | * Get the name of a given file without the extension. |
||
123 | * |
||
124 | * @param string $filePath A file path |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | 39 | public function getBaseName($filePath) |
|
132 | |||
133 | /** |
||
134 | * Get the name of a given file. |
||
135 | * |
||
136 | * @param string $filePath A file path |
||
137 | * |
||
138 | * @return string |
||
139 | */ |
||
140 | 29 | public function getFileName($filePath) |
|
144 | |||
145 | /** |
||
146 | * Get the parent directory of a given file. |
||
147 | * |
||
148 | * @param string $filePath A file path |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | 33 | public function getFolderPath($filePath) |
|
156 | |||
157 | /** |
||
158 | * Get the extension of a given file. |
||
159 | * |
||
160 | * @param string $filename A file path |
||
161 | * |
||
162 | * @return string The extension of the file |
||
163 | */ |
||
164 | 120 | public function getExtension($filename) |
|
168 | |||
169 | /** |
||
170 | * Check whether or not if a given path is a directory. |
||
171 | * |
||
172 | * @param string $folderPath |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | 29 | public function isDir($folderPath) |
|
180 | |||
181 | /** |
||
182 | * Check whether a given file path is a symlink |
||
183 | * |
||
184 | * @param string $filePath |
||
185 | * |
||
186 | * @return bool |
||
187 | */ |
||
188 | 9 | public function isSymlink($filePath) |
|
192 | |||
193 | /** |
||
194 | * Only read a file's contents if it's within the current working directory |
||
195 | * |
||
196 | * @param string $filePath |
||
197 | * |
||
198 | * @return bool|string |
||
199 | */ |
||
200 | 30 | public function safeReadFile($filePath) |
|
214 | |||
215 | /** |
||
216 | * Get the full path to the file without the extension. |
||
217 | * |
||
218 | * @param string $filename A file path |
||
219 | * |
||
220 | * @return string |
||
221 | */ |
||
222 | 4 | public function removeExtension($filename) |
|
229 | } |
||
230 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.