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