1 | <?php |
||
14 | class FileSystemHelper |
||
15 | { |
||
16 | /** @var string Real path of the base folder where all the I/O can occur */ |
||
17 | protected $baseFolderRealPath; |
||
18 | |||
19 | /** |
||
20 | * @param string $baseFolderPath The path of the base folder where all the I/O can occur |
||
21 | */ |
||
22 | 276 | public function __construct($baseFolderPath) |
|
26 | |||
27 | /** |
||
28 | * Creates an empty folder with the given name under the given parent folder. |
||
29 | * |
||
30 | * @param string $parentFolderPath The parent folder path under which the folder is going to be created |
||
31 | * @param string $folderName The name of the folder to create |
||
32 | * @return string Path of the created folder |
||
33 | * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or if the folder path is not inside of the base folder |
||
34 | */ |
||
35 | 267 | public function createFolder($parentFolderPath, $folderName) |
|
48 | |||
49 | /** |
||
50 | * Creates a file with the given name and content in the given folder. |
||
51 | * The parent folder must exist. |
||
52 | * |
||
53 | * @param string $parentFolderPath The parent folder path where the file is going to be created |
||
54 | * @param string $fileName The name of the file to create |
||
55 | * @param string $fileContents The contents of the file to create |
||
56 | * @return string Path of the created file |
||
57 | * @throws \Box\Spout\Common\Exception\IOException If unable to create the file or if the file path is not inside of the base folder |
||
58 | */ |
||
59 | 243 | public function createFileWithContents($parentFolderPath, $fileName, $fileContents) |
|
72 | |||
73 | /** |
||
74 | * Delete the file at the given path |
||
75 | * |
||
76 | * @param string $filePath Path of the file to delete |
||
77 | * @return void |
||
78 | * @throws \Box\Spout\Common\Exception\IOException If the file path is not inside of the base folder |
||
79 | */ |
||
80 | 186 | public function deleteFile($filePath) |
|
88 | |||
89 | /** |
||
90 | * Delete the folder at the given path as well as all its contents |
||
91 | * |
||
92 | * @param string $folderPath Path of the folder to delete |
||
93 | * @return void |
||
94 | * @throws \Box\Spout\Common\Exception\IOException If the folder path is not inside of the base folder |
||
95 | */ |
||
96 | 210 | public function deleteFolderRecursively($folderPath) |
|
115 | |||
116 | /** |
||
117 | * All I/O operations must occur inside the base folder, for security reasons. |
||
118 | * This function will throw an exception if the folder where the I/O operation |
||
119 | * should occur is not inside the base folder. |
||
120 | * |
||
121 | * @param string $operationFolderPath The path of the folder where the I/O operation should occur |
||
122 | * @return void |
||
123 | * @throws \Box\Spout\Common\Exception\IOException If the folder where the I/O operation should occur is not inside the base folder |
||
124 | */ |
||
125 | 276 | protected function throwIfOperationNotInBaseFolder($operationFolderPath) |
|
133 | } |
||
134 |