Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| AbstractStorage | |
100.00% |
5 / 5 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setAdapter | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getAdapter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| adapter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setBaseDir | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getBaseDir | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getCurrentDir | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| chdir | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| mkdir | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| rmdir | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| listAll | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| listDirs | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| listFiles | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| putFile | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| putFileContents | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| putFileStream | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| uploadFile | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| copyFile | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| copyFileToExternal | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| copyFileFromExternal | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| moveFileToExternal | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| moveFileFromExternal | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| renameFile | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| replaceFileContents | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| deleteFile | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| fetchFile | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| fetchFileStream | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| fetchFileInfo | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getTemporaryUrl | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| fileExists | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| isDir | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| isFile | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getFileSize | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getFileType | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getFileMTime | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| md5File | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Storage; |
| 16 | |
| 17 | use Pop\Storage\Adapter\AbstractAdapter; |
| 18 | |
| 19 | /** |
| 20 | * Storage abstract class |
| 21 | * |
| 22 | * @category Pop |
| 23 | * @package Pop\Storage |
| 24 | * @author Nick Sagona, III <nick@popphp.org> |
| 25 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 26 | * @license https://www.popphp.org/license New BSD License |
| 27 | * @version 3.0.0 |
| 28 | */ |
| 29 | abstract class AbstractStorage implements StorageInterface |
| 30 | { |
| 31 | |
| 32 | /** |
| 33 | * Storage adapter |
| 34 | * @var ?AbstractAdapter |
| 35 | */ |
| 36 | protected ?AbstractAdapter $adapter = null; |
| 37 | |
| 38 | /** |
| 39 | * Constructor |
| 40 | * |
| 41 | * @param AbstractAdapter $adapter |
| 42 | */ |
| 43 | public function __construct(AbstractAdapter $adapter) |
| 44 | { |
| 45 | $this->setAdapter($adapter); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Set adapter |
| 50 | * |
| 51 | * @param AbstractAdapter $adapter |
| 52 | * @return AbstractStorage |
| 53 | */ |
| 54 | public function setAdapter(AbstractAdapter $adapter): AbstractStorage |
| 55 | { |
| 56 | $this->adapter = $adapter; |
| 57 | return $this; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Get adapter |
| 62 | * |
| 63 | * @return ?AbstractAdapter |
| 64 | */ |
| 65 | public function getAdapter(): ?AbstractAdapter |
| 66 | { |
| 67 | return $this->adapter; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Get adapter (alias) |
| 72 | * |
| 73 | * @return ?AbstractAdapter |
| 74 | */ |
| 75 | public function adapter(): ?AbstractAdapter |
| 76 | { |
| 77 | return $this->adapter; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Set base directory |
| 82 | * |
| 83 | * @param ?string $directory |
| 84 | * @return void |
| 85 | */ |
| 86 | abstract public function setBaseDir(?string $directory = null): void; |
| 87 | |
| 88 | /** |
| 89 | * Get base directory |
| 90 | * |
| 91 | * @return ?string |
| 92 | */ |
| 93 | abstract public function getBaseDir(): ?string; |
| 94 | |
| 95 | /** |
| 96 | * Get current directory |
| 97 | * |
| 98 | * @return ?string |
| 99 | */ |
| 100 | abstract public function getCurrentDir(): ?string; |
| 101 | |
| 102 | /** |
| 103 | * Change directory |
| 104 | * |
| 105 | * @param ?string $directory |
| 106 | * @return void |
| 107 | */ |
| 108 | abstract public function chdir(?string $directory = null): void; |
| 109 | |
| 110 | /** |
| 111 | * Make directory |
| 112 | * |
| 113 | * @param string $directory |
| 114 | * @return void |
| 115 | */ |
| 116 | abstract public function mkdir(string $directory): void; |
| 117 | |
| 118 | /** |
| 119 | * Remove a directory |
| 120 | * |
| 121 | * @param string $directory |
| 122 | * @return void |
| 123 | */ |
| 124 | abstract public function rmdir(string $directory): void; |
| 125 | |
| 126 | /** |
| 127 | * List all |
| 128 | * |
| 129 | * @param ?string $search |
| 130 | * @param bool $recursive |
| 131 | * @return array |
| 132 | */ |
| 133 | abstract public function listAll(?string $search = null, bool $recursive = false): array; |
| 134 | |
| 135 | /** |
| 136 | * List directories |
| 137 | * |
| 138 | * @param ?string $search |
| 139 | * @param bool $recursive |
| 140 | * @return array |
| 141 | */ |
| 142 | abstract public function listDirs(?string $search = null, bool $recursive = false): array; |
| 143 | |
| 144 | /** |
| 145 | * List files |
| 146 | * |
| 147 | * @param ?string $search |
| 148 | * @param bool $recursive |
| 149 | * @return array |
| 150 | */ |
| 151 | abstract public function listFiles(?string $search = null, bool $recursive = false): array; |
| 152 | |
| 153 | /** |
| 154 | * Put file |
| 155 | * |
| 156 | * @param string $fileFrom |
| 157 | * @param bool $copy |
| 158 | * @return void |
| 159 | */ |
| 160 | abstract public function putFile(string $fileFrom, bool $copy = true): void; |
| 161 | |
| 162 | /** |
| 163 | * Put file contents |
| 164 | * |
| 165 | * @param string $filename |
| 166 | * @param string $fileContents |
| 167 | * @return void |
| 168 | */ |
| 169 | abstract public function putFileContents(string $filename, string $fileContents): void; |
| 170 | |
| 171 | /** |
| 172 | * Put file from a stream resource |
| 173 | * |
| 174 | * @param string $filename |
| 175 | * @param mixed $resource |
| 176 | * @return void |
| 177 | */ |
| 178 | abstract public function putFileStream(string $filename, mixed $resource): void; |
| 179 | |
| 180 | /** |
| 181 | * Upload file from server request $_FILES['file'] |
| 182 | * |
| 183 | * @param array $file |
| 184 | * @return void |
| 185 | */ |
| 186 | abstract public function uploadFile(array $file): void; |
| 187 | |
| 188 | /** |
| 189 | * Copy file |
| 190 | * |
| 191 | * @param string $sourceFile |
| 192 | * @param string $destFile |
| 193 | * @return void |
| 194 | */ |
| 195 | abstract public function copyFile(string $sourceFile, string $destFile): void; |
| 196 | |
| 197 | /** |
| 198 | * Copy file to a location external to the current location |
| 199 | * |
| 200 | * @param string $sourceFile |
| 201 | * @param string $externalFile |
| 202 | * @return void |
| 203 | */ |
| 204 | abstract public function copyFileToExternal(string $sourceFile, string $externalFile): void; |
| 205 | |
| 206 | /** |
| 207 | * Copy file from a location external to the current location |
| 208 | * |
| 209 | * @param string $externalFile |
| 210 | * @param string $destFile |
| 211 | * @return void |
| 212 | */ |
| 213 | abstract public function copyFileFromExternal(string $externalFile, string $destFile): void; |
| 214 | |
| 215 | /** |
| 216 | * Move file to a location external to the current location |
| 217 | * |
| 218 | * @param string $sourceFile |
| 219 | * @param string $externalFile |
| 220 | * @return void |
| 221 | */ |
| 222 | abstract public function moveFileToExternal(string $sourceFile, string $externalFile): void; |
| 223 | |
| 224 | /** |
| 225 | * Move file from a location external to the current location |
| 226 | * |
| 227 | * @param string $externalFile |
| 228 | * @param string $destFile |
| 229 | * @return void |
| 230 | */ |
| 231 | abstract public function moveFileFromExternal(string $externalFile, string $destFile): void; |
| 232 | |
| 233 | /** |
| 234 | * Rename file |
| 235 | * |
| 236 | * @param string $oldFile |
| 237 | * @param string $newFile |
| 238 | * @return void |
| 239 | */ |
| 240 | abstract public function renameFile(string $oldFile, string $newFile): void; |
| 241 | |
| 242 | /** |
| 243 | * Replace file |
| 244 | * |
| 245 | * @param string $filename |
| 246 | * @param string $fileContents |
| 247 | * @return void |
| 248 | */ |
| 249 | abstract public function replaceFileContents(string $filename, string $fileContents): void; |
| 250 | |
| 251 | /** |
| 252 | * Delete file |
| 253 | * |
| 254 | * @param string $filename |
| 255 | * @return void |
| 256 | */ |
| 257 | abstract public function deleteFile(string $filename): void; |
| 258 | |
| 259 | /** |
| 260 | * Fetch file contents |
| 261 | * |
| 262 | * @param string $filename |
| 263 | * @return mixed |
| 264 | */ |
| 265 | abstract public function fetchFile(string $filename): mixed; |
| 266 | |
| 267 | /** |
| 268 | * Fetch file as a stream resource |
| 269 | * |
| 270 | * @param string $filename |
| 271 | * @return mixed |
| 272 | */ |
| 273 | abstract public function fetchFileStream(string $filename): mixed; |
| 274 | |
| 275 | /** |
| 276 | * Fetch file info |
| 277 | * |
| 278 | * @param string $filename |
| 279 | * @return array |
| 280 | */ |
| 281 | abstract public function fetchFileInfo(string $filename): array; |
| 282 | |
| 283 | /** |
| 284 | * Get a temporary (presigned) URL for the file, valid for $expiresInSeconds |
| 285 | * |
| 286 | * @param string $filename |
| 287 | * @param int $expiresInSeconds |
| 288 | * @return string |
| 289 | */ |
| 290 | abstract public function getTemporaryUrl(string $filename, int $expiresInSeconds = 900): string; |
| 291 | |
| 292 | /** |
| 293 | * File exists |
| 294 | * |
| 295 | * @param string $filename |
| 296 | * @return bool |
| 297 | */ |
| 298 | abstract public function fileExists(string $filename): bool; |
| 299 | |
| 300 | /** |
| 301 | * Check if is a dir |
| 302 | * |
| 303 | * @param string $directory |
| 304 | * @return bool |
| 305 | */ |
| 306 | abstract public function isDir(string $directory): bool; |
| 307 | |
| 308 | /** |
| 309 | * Check if is a file |
| 310 | * |
| 311 | * @param string $filename |
| 312 | * @return bool |
| 313 | */ |
| 314 | abstract public function isFile(string $filename): bool; |
| 315 | |
| 316 | /** |
| 317 | * Get file size |
| 318 | * |
| 319 | * @param string $filename |
| 320 | * @return int |
| 321 | */ |
| 322 | abstract public function getFileSize(string $filename): int; |
| 323 | |
| 324 | /** |
| 325 | * Get file type |
| 326 | * |
| 327 | * @param string $filename |
| 328 | * @return string |
| 329 | */ |
| 330 | abstract public function getFileType(string $filename): string; |
| 331 | |
| 332 | /** |
| 333 | * Get file modified time |
| 334 | * |
| 335 | * @param string $filename |
| 336 | * @return int|string |
| 337 | */ |
| 338 | abstract public function getFileMTime(string $filename): int|string; |
| 339 | |
| 340 | /** |
| 341 | * Create MD5 checksum of the file |
| 342 | * |
| 343 | * @param string $filename |
| 344 | * @return string |
| 345 | */ |
| 346 | abstract public function md5File(string $filename): string; |
| 347 | |
| 348 | } |