@@ -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,6 +147,8 @@ 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 ->prependPrefix ('' ), '' , $ bunny_file_array ['Path ' ]);
151
+
150
152
return match ($ bunny_file_array ['IsDirectory ' ]) {
151
153
true => new DirectoryAttributes (
152
154
Util::normalizePath (
@@ -204,7 +206,7 @@ private function extractExtraMetadata(array $bunny_file_array): array
204
206
*/
205
207
public function detectMimeType (string $ path ): string
206
208
{
207
- $ this ->prependPrefix ($ path );
209
+ $ path = $ this ->prependPrefix ($ path );
208
210
209
211
try {
210
212
$ detector = new FinfoMimeTypeDetector ();
@@ -228,7 +230,7 @@ public function detectMimeType(string $path): string
228
230
*/
229
231
public function writeStream ($ path , $ contents , Config $ config ): void
230
232
{
231
- $ this ->prependPrefix ($ path );
233
+ $ path = $ this ->prependPrefix ($ path );
232
234
233
235
$ this ->write ($ path , stream_get_contents ($ contents ), $ config );
234
236
}
@@ -241,6 +243,8 @@ public function writeStream($path, $contents, Config $config): void
241
243
*/
242
244
public function readStream ($ path )
243
245
{
246
+ $ path = $ this ->prependPrefix ($ path );
247
+
244
248
try {
245
249
return $ this ->client ->stream ($ path );
246
250
// @codeCoverageIgnoreStart
@@ -256,7 +260,7 @@ public function readStream($path)
256
260
*/
257
261
public function deleteDirectory (string $ path ): void
258
262
{
259
- $ this ->prependPrefix ($ path );
263
+ $ path = $ this ->prependPrefix ($ path );
260
264
261
265
try {
262
266
$ this ->client ->delete (
@@ -275,7 +279,7 @@ public function deleteDirectory(string $path): void
275
279
*/
276
280
public function createDirectory (string $ path , Config $ config ): void
277
281
{
278
- $ this ->prependPrefix ($ path );
282
+ $ path = $ this ->prependPrefix ($ path );
279
283
280
284
try {
281
285
$ this ->client ->make_directory ($ path );
@@ -296,7 +300,7 @@ public function createDirectory(string $path, Config $config): void
296
300
*/
297
301
public function setVisibility (string $ path , string $ visibility ): void
298
302
{
299
- $ this ->prependPrefix ($ path );
303
+ $ path = $ this ->prependPrefix ($ path );
300
304
301
305
throw UnableToSetVisibility::atLocation ($ path , 'BunnyCDN does not support visibility ' );
302
306
}
@@ -306,7 +310,7 @@ public function setVisibility(string $path, string $visibility): void
306
310
*/
307
311
public function visibility (string $ path ): FileAttributes
308
312
{
309
- $ this ->prependPrefix ($ path );
313
+ $ path = $ this ->prependPrefix ($ path );
310
314
311
315
try {
312
316
return new FileAttributes ($ this ->getObject ($ path )->path (), null , $ this ->pullzone_url ? 'public ' : 'private ' );
@@ -323,7 +327,7 @@ public function visibility(string $path): FileAttributes
323
327
*/
324
328
public function mimeType (string $ path ): FileAttributes
325
329
{
326
- $ this ->prependPrefix ($ path );
330
+ $ path = $ this ->prependPrefix ($ path );
327
331
328
332
try {
329
333
$ object = $ this ->getObject ($ path );
@@ -363,12 +367,12 @@ public function mimeType(string $path): FileAttributes
363
367
*/
364
368
protected function getObject (string $ path = '' ): StorageAttributes
365
369
{
366
- $ this ->prependPrefix ($ path );
367
-
368
370
$ directory = pathinfo ($ path , PATHINFO_DIRNAME );
369
371
$ list = (new DirectoryListing ($ this ->listContents ($ directory )))
370
372
->filter (function (StorageAttributes $ item ) use ($ path ) {
371
- return $ item ->path () === $ path ;
373
+ $ itemPath = $ this ->prependPrefix (Util::normalizePath ($ item ->path ()));
374
+
375
+ return $ itemPath === $ path ;
372
376
})->toArray ();
373
377
374
378
if (count ($ list ) === 1 ) {
@@ -390,7 +394,7 @@ protected function getObject(string $path = ''): StorageAttributes
390
394
*/
391
395
public function lastModified (string $ path ): FileAttributes
392
396
{
393
- $ this ->prependPrefix ($ path );
397
+ $ path = $ this ->prependPrefix ($ path );
394
398
395
399
try {
396
400
return $ this ->getObject ($ path );
@@ -407,7 +411,7 @@ public function lastModified(string $path): FileAttributes
407
411
*/
408
412
public function fileSize (string $ path ): FileAttributes
409
413
{
410
- $ this ->prependPrefix ($ path );
414
+ $ path = $ this ->prependPrefix ($ path );
411
415
412
416
try {
413
417
return $ this ->getObject ($ path );
@@ -424,8 +428,8 @@ public function fileSize(string $path): FileAttributes
424
428
*/
425
429
public function move (string $ source , string $ destination , Config $ config ): void
426
430
{
427
- $ this ->prependPrefix ($ source );
428
- $ this ->prependPrefix ($ destination );
431
+ $ source = $ this ->prependPrefix ($ source );
432
+ $ destination = $ this ->prependPrefix ($ destination );
429
433
430
434
try {
431
435
$ this ->write ($ destination , $ this ->read ($ source ), new Config ());
@@ -441,7 +445,7 @@ public function move(string $source, string $destination, Config $config): void
441
445
*/
442
446
public function delete ($ path ): void
443
447
{
444
- $ this ->prependPrefix ($ path );
448
+ $ path = $ this ->prependPrefix ($ path );
445
449
446
450
try {
447
451
$ this ->client ->delete ($ path );
@@ -468,14 +472,16 @@ public function directoryExists(string $path): bool
468
472
*/
469
473
public function fileExists (string $ path ): bool
470
474
{
471
- $ this ->prependPrefix ($ path );
475
+ $ path = $ this ->prependPrefix ($ path );
472
476
473
477
$ list = new DirectoryListing ($ this ->listContents (
474
478
Util::splitPathIntoDirectoryAndFile ($ path )['dir ' ]
475
479
));
476
480
477
481
$ count = $ list ->filter (function (StorageAttributes $ item ) use ($ path ) {
478
- return Util::normalizePath ($ item ->path ()) === Util::normalizePath ($ path );
482
+ $ itemPath = $ this ->prependPrefix (Util::normalizePath ($ item ->path ()));
483
+
484
+ return $ itemPath === Util::normalizePath ($ path );
479
485
})->toArray ();
480
486
481
487
return (bool ) count ($ count );
@@ -503,20 +509,20 @@ private static function parse_bunny_timestamp(string $timestamp): int
503
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 ();
504
510
}
505
511
506
- private function prependPrefix (string & $ path ): void
512
+ private function prependPrefix (string $ path ): string
507
513
{
508
514
if ($ this ->prefixPath === '' ) {
509
- return ;
515
+ return $ path ;
510
516
}
511
517
512
518
if ($ path === $ this ->prefixPath ) {
513
- return ;
519
+ return $ path ;
514
520
}
515
521
516
522
if (\str_starts_with ($ path , $ this ->prefixPath .'/ ' )) {
517
- return ;
523
+ return $ path ;
518
524
}
519
525
520
- $ path = $ this ->prefixPath .'/ ' .$ path ;
526
+ return $ this ->prefixPath .'/ ' .$ path ;
521
527
}
522
528
}
0 commit comments