@@ -147,12 +147,12 @@ 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 ' ]);
150
+ $ bunny_file_array ['Path ' ] = $ this -> replaceFirst ($ this ->prependPrefix ('' ), '' , $ bunny_file_array ['Path ' ]);
151
151
152
152
return match ($ bunny_file_array ['IsDirectory ' ]) {
153
153
true => new DirectoryAttributes (
154
154
Util::normalizePath (
155
- str_replace (
155
+ $ this -> replaceFirst (
156
156
$ bunny_file_array ['StorageZoneName ' ].'/ ' ,
157
157
'/ ' ,
158
158
$ bunny_file_array ['Path ' ].$ bunny_file_array ['ObjectName ' ]
@@ -161,7 +161,7 @@ protected function normalizeObject(array $bunny_file_array): StorageAttributes
161
161
),
162
162
false => new FileAttributes (
163
163
Util::normalizePath (
164
- str_replace (
164
+ $ this -> replaceFirst (
165
165
$ bunny_file_array ['StorageZoneName ' ].'/ ' ,
166
166
'/ ' ,
167
167
$ bunny_file_array ['Path ' ].$ bunny_file_array ['ObjectName ' ]
@@ -525,4 +525,15 @@ private function prependPrefix(string $path): string
525
525
526
526
return $ this ->prefixPath .'/ ' .$ path ;
527
527
}
528
+
529
+ private function replaceFirst ($ search , $ replace , $ subject )
530
+ {
531
+ $ position = strpos ($ subject , $ search );
532
+
533
+ if ($ position !== false ) {
534
+ return substr_replace ($ subject , $ replace , $ position , strlen ($ search ));
535
+ }
536
+
537
+ return $ subject ;
538
+ }
528
539
}
0 commit comments