@@ -65,8 +65,8 @@ public function __construct(BunnyCDNClient $client, string $pullzone_url = '', s
65
65
*/
66
66
public function copy ($ source , $ destination , Config $ config ): void
67
67
{
68
- $ this ->prependPrefix ($ source );
69
- $ this ->prependPrefix ($ destination );
68
+ $ source = $ this ->prependPrefix ($ source );
69
+ $ destination = $ this ->prependPrefix ($ destination );
70
70
71
71
try {
72
72
$ this ->write ($ destination , $ this ->read ($ source ), new Config ());
@@ -84,7 +84,7 @@ public function copy($source, $destination, Config $config): void
84
84
*/
85
85
public function write ($ path , $ contents , Config $ config ): void
86
86
{
87
- $ this ->prependPrefix ($ path );
87
+ $ path = $ this ->prependPrefix ($ path );
88
88
89
89
try {
90
90
$ this ->client ->upload ($ path , $ contents );
@@ -101,7 +101,7 @@ public function write($path, $contents, Config $config): void
101
101
*/
102
102
public function read ($ path ): string
103
103
{
104
- $ this ->prependPrefix ($ path );
104
+ $ path = $ this ->prependPrefix ($ path );
105
105
106
106
try {
107
107
return $ this ->client ->download ($ path );
@@ -119,7 +119,7 @@ public function read($path): string
119
119
*/
120
120
public function listContents (string $ path = '' , bool $ deep = false ): iterable
121
121
{
122
- $ this ->prependPrefix ($ path );
122
+ $ path = $ this ->prependPrefix ($ path );
123
123
124
124
try {
125
125
$ entries = $ this ->client ->list ($ path );
@@ -147,7 +147,7 @@ public function listContents(string $path = '', bool $deep = false): iterable
147
147
*/
148
148
protected function normalizeObject (array $ bunny_file_array ): StorageAttributes
149
149
{
150
- $ bunny_file_array ['Path ' ] = str_replace ($ this ->prefixPath , '' , $ bunny_file_array ['Path ' ]);
150
+ $ bunny_file_array ['Path ' ] = str_replace ($ this ->prependPrefix ( '' ) , '' , $ bunny_file_array ['Path ' ]);
151
151
152
152
return match ($ bunny_file_array ['IsDirectory ' ]) {
153
153
true => new DirectoryAttributes (
@@ -206,7 +206,7 @@ private function extractExtraMetadata(array $bunny_file_array): array
206
206
*/
207
207
public function detectMimeType (string $ path ): string
208
208
{
209
- $ this ->prependPrefix ($ path );
209
+ $ path = $ this ->prependPrefix ($ path );
210
210
211
211
try {
212
212
$ detector = new FinfoMimeTypeDetector ();
@@ -230,7 +230,7 @@ public function detectMimeType(string $path): string
230
230
*/
231
231
public function writeStream ($ path , $ contents , Config $ config ): void
232
232
{
233
- $ this ->prependPrefix ($ path );
233
+ $ path = $ this ->prependPrefix ($ path );
234
234
235
235
$ this ->write ($ path , stream_get_contents ($ contents ), $ config );
236
236
}
@@ -243,7 +243,7 @@ public function writeStream($path, $contents, Config $config): void
243
243
*/
244
244
public function readStream ($ path )
245
245
{
246
- $ this ->prependPrefix ($ path );
246
+ $ path = $ this ->prependPrefix ($ path );
247
247
248
248
try {
249
249
return $ this ->client ->stream ($ path );
@@ -260,7 +260,7 @@ public function readStream($path)
260
260
*/
261
261
public function deleteDirectory (string $ path ): void
262
262
{
263
- $ this ->prependPrefix ($ path );
263
+ $ path = $ this ->prependPrefix ($ path );
264
264
265
265
try {
266
266
$ this ->client ->delete (
@@ -279,7 +279,7 @@ public function deleteDirectory(string $path): void
279
279
*/
280
280
public function createDirectory (string $ path , Config $ config ): void
281
281
{
282
- $ this ->prependPrefix ($ path );
282
+ $ path = $ this ->prependPrefix ($ path );
283
283
284
284
try {
285
285
$ this ->client ->make_directory ($ path );
@@ -300,7 +300,7 @@ public function createDirectory(string $path, Config $config): void
300
300
*/
301
301
public function setVisibility (string $ path , string $ visibility ): void
302
302
{
303
- $ this ->prependPrefix ($ path );
303
+ $ path = $ this ->prependPrefix ($ path );
304
304
305
305
throw UnableToSetVisibility::atLocation ($ path , 'BunnyCDN does not support visibility ' );
306
306
}
@@ -310,6 +310,8 @@ public function setVisibility(string $path, string $visibility): void
310
310
*/
311
311
public function visibility (string $ path ): FileAttributes
312
312
{
313
+ $ path = $ this ->prependPrefix ($ path );
314
+
313
315
try {
314
316
return new FileAttributes ($ this ->getObject ($ path )->path (), null , $ this ->pullzone_url ? 'public ' : 'private ' );
315
317
} catch (UnableToReadFile |TypeError $ e ) {
@@ -325,6 +327,8 @@ public function visibility(string $path): FileAttributes
325
327
*/
326
328
public function mimeType (string $ path ): FileAttributes
327
329
{
330
+ $ path = $ this ->prependPrefix ($ path );
331
+
328
332
try {
329
333
$ object = $ this ->getObject ($ path );
330
334
@@ -366,7 +370,9 @@ protected function getObject(string $path = ''): StorageAttributes
366
370
$ directory = pathinfo ($ path , PATHINFO_DIRNAME );
367
371
$ list = (new DirectoryListing ($ this ->listContents ($ directory )))
368
372
->filter (function (StorageAttributes $ item ) use ($ path ) {
369
- return $ item ->path () === $ path ;
373
+ $ itemPath = $ this ->prependPrefix (Util::normalizePath ($ item ->path ()));
374
+
375
+ return $ itemPath === $ path ;
370
376
})->toArray ();
371
377
372
378
if (count ($ list ) === 1 ) {
@@ -388,6 +394,8 @@ protected function getObject(string $path = ''): StorageAttributes
388
394
*/
389
395
public function lastModified (string $ path ): FileAttributes
390
396
{
397
+ $ path = $ this ->prependPrefix ($ path );
398
+
391
399
try {
392
400
return $ this ->getObject ($ path );
393
401
} catch (UnableToReadFile $ e ) {
@@ -403,6 +411,8 @@ public function lastModified(string $path): FileAttributes
403
411
*/
404
412
public function fileSize (string $ path ): FileAttributes
405
413
{
414
+ $ path = $ this ->prependPrefix ($ path );
415
+
406
416
try {
407
417
return $ this ->getObject ($ path );
408
418
} catch (UnableToReadFile $ e ) {
@@ -418,8 +428,8 @@ public function fileSize(string $path): FileAttributes
418
428
*/
419
429
public function move (string $ source , string $ destination , Config $ config ): void
420
430
{
421
- $ this ->prependPrefix ($ source );
422
- $ this ->prependPrefix ($ destination );
431
+ $ source = $ this ->prependPrefix ($ source );
432
+ $ destination = $ this ->prependPrefix ($ destination );
423
433
424
434
try {
425
435
$ this ->write ($ destination , $ this ->read ($ source ), new Config ());
@@ -435,7 +445,7 @@ public function move(string $source, string $destination, Config $config): void
435
445
*/
436
446
public function delete ($ path ): void
437
447
{
438
- $ this ->prependPrefix ($ path );
448
+ $ path = $ this ->prependPrefix ($ path );
439
449
440
450
try {
441
451
$ this ->client ->delete ($ path );
@@ -462,12 +472,16 @@ public function directoryExists(string $path): bool
462
472
*/
463
473
public function fileExists (string $ path ): bool
464
474
{
475
+ $ path = $ this ->prependPrefix ($ path );
476
+
465
477
$ list = new DirectoryListing ($ this ->listContents (
466
478
Util::splitPathIntoDirectoryAndFile ($ path )['dir ' ]
467
479
));
468
480
469
481
$ count = $ list ->filter (function (StorageAttributes $ item ) use ($ path ) {
470
- return Util::normalizePath ($ item ->path ()) === Util::normalizePath ($ path );
482
+ $ itemPath = $ this ->prependPrefix (Util::normalizePath ($ item ->path ()));
483
+
484
+ return $ itemPath === Util::normalizePath ($ path );
471
485
})->toArray ();
472
486
473
487
return (bool ) count ($ count );
@@ -495,20 +509,20 @@ private static function parse_bunny_timestamp(string $timestamp): int
495
509
return (date_create_from_format ('Y-m-d\TH:i:s.u ' , $ timestamp ) ?: date_create_from_format ('Y-m-d\TH:i:s ' , $ timestamp ))->getTimestamp ();
496
510
}
497
511
498
- private function prependPrefix (string & $ path ): void
512
+ private function prependPrefix (string $ path ): string
499
513
{
500
514
if ($ this ->prefixPath === '' ) {
501
- return ;
515
+ return $ path ;
502
516
}
503
517
504
518
if ($ path === $ this ->prefixPath ) {
505
- return ;
519
+ return $ path ;
506
520
}
507
521
508
522
if (\str_starts_with ($ path , $ this ->prefixPath .'/ ' )) {
509
- return ;
523
+ return $ path ;
510
524
}
511
525
512
- $ path = $ this ->prefixPath .'/ ' .$ path ;
526
+ return $ this ->prefixPath .'/ ' .$ path ;
513
527
}
514
528
}
0 commit comments