@@ -23,11 +23,11 @@ class Encoding extends Wrapper {
2323 private CappedMemoryCache $ namesCache ;
2424
2525 /**
26- * @param array $parameters
26+ * @param array{storage: IStorage, ...} $parameters
2727 */
2828 public function __construct (array $ parameters ) {
29- $ this ->storage = $ parameters ['storage ' ];
3029 $ this ->namesCache = new CappedMemoryCache ();
30+ parent ::__construct ($ parameters );
3131 }
3232
3333 /**
@@ -74,7 +74,7 @@ private function findPathToUse(string $fullPath): string {
7474 */
7575 private function findPathToUseLastSection (string $ basePath , string $ lastSection ): ?string {
7676 $ fullPath = $ basePath . $ lastSection ;
77- if ($ lastSection === '' || $ this ->isAscii ($ lastSection ) || $ this ->storage ->file_exists ($ fullPath )) {
77+ if ($ lastSection === '' || $ this ->isAscii ($ lastSection ) || $ this ->getWrapperStorage () ->file_exists ($ fullPath )) {
7878 $ this ->namesCache [$ fullPath ] = $ fullPath ;
7979 return $ fullPath ;
8080 }
@@ -86,7 +86,7 @@ private function findPathToUseLastSection(string $basePath, string $lastSection)
8686 $ otherFormPath = \Normalizer::normalize ($ lastSection , \Normalizer::FORM_C );
8787 }
8888 $ otherFullPath = $ basePath . $ otherFormPath ;
89- if ($ this ->storage ->file_exists ($ otherFullPath )) {
89+ if ($ this ->getWrapperStorage () ->file_exists ($ otherFullPath )) {
9090 $ this ->namesCache [$ fullPath ] = $ otherFullPath ;
9191 return $ otherFullPath ;
9292 }
@@ -98,88 +98,88 @@ private function findPathToUseLastSection(string $basePath, string $lastSection)
9898
9999 public function mkdir (string $ path ): bool {
100100 // note: no conversion here, method should not be called with non-NFC names!
101- $ result = $ this ->storage ->mkdir ($ path );
101+ $ result = $ this ->getWrapperStorage () ->mkdir ($ path );
102102 if ($ result ) {
103103 $ this ->namesCache [$ path ] = $ path ;
104104 }
105105 return $ result ;
106106 }
107107
108108 public function rmdir (string $ path ): bool {
109- $ result = $ this ->storage ->rmdir ($ this ->findPathToUse ($ path ));
109+ $ result = $ this ->getWrapperStorage () ->rmdir ($ this ->findPathToUse ($ path ));
110110 if ($ result ) {
111111 unset($ this ->namesCache [$ path ]);
112112 }
113113 return $ result ;
114114 }
115115
116116 public function opendir (string $ path ) {
117- $ handle = $ this ->storage ->opendir ($ this ->findPathToUse ($ path ));
117+ $ handle = $ this ->getWrapperStorage () ->opendir ($ this ->findPathToUse ($ path ));
118118 return EncodingDirectoryWrapper::wrap ($ handle );
119119 }
120120
121121 public function is_dir (string $ path ): bool {
122- return $ this ->storage ->is_dir ($ this ->findPathToUse ($ path ));
122+ return $ this ->getWrapperStorage () ->is_dir ($ this ->findPathToUse ($ path ));
123123 }
124124
125125 public function is_file (string $ path ): bool {
126- return $ this ->storage ->is_file ($ this ->findPathToUse ($ path ));
126+ return $ this ->getWrapperStorage () ->is_file ($ this ->findPathToUse ($ path ));
127127 }
128128
129129 public function stat (string $ path ): array |false {
130- return $ this ->storage ->stat ($ this ->findPathToUse ($ path ));
130+ return $ this ->getWrapperStorage () ->stat ($ this ->findPathToUse ($ path ));
131131 }
132132
133133 public function filetype (string $ path ): string |false {
134- return $ this ->storage ->filetype ($ this ->findPathToUse ($ path ));
134+ return $ this ->getWrapperStorage () ->filetype ($ this ->findPathToUse ($ path ));
135135 }
136136
137137 public function filesize (string $ path ): int |float |false {
138- return $ this ->storage ->filesize ($ this ->findPathToUse ($ path ));
138+ return $ this ->getWrapperStorage () ->filesize ($ this ->findPathToUse ($ path ));
139139 }
140140
141141 public function isCreatable (string $ path ): bool {
142- return $ this ->storage ->isCreatable ($ this ->findPathToUse ($ path ));
142+ return $ this ->getWrapperStorage () ->isCreatable ($ this ->findPathToUse ($ path ));
143143 }
144144
145145 public function isReadable (string $ path ): bool {
146- return $ this ->storage ->isReadable ($ this ->findPathToUse ($ path ));
146+ return $ this ->getWrapperStorage () ->isReadable ($ this ->findPathToUse ($ path ));
147147 }
148148
149149 public function isUpdatable (string $ path ): bool {
150- return $ this ->storage ->isUpdatable ($ this ->findPathToUse ($ path ));
150+ return $ this ->getWrapperStorage () ->isUpdatable ($ this ->findPathToUse ($ path ));
151151 }
152152
153153 public function isDeletable (string $ path ): bool {
154- return $ this ->storage ->isDeletable ($ this ->findPathToUse ($ path ));
154+ return $ this ->getWrapperStorage () ->isDeletable ($ this ->findPathToUse ($ path ));
155155 }
156156
157157 public function isSharable (string $ path ): bool {
158- return $ this ->storage ->isSharable ($ this ->findPathToUse ($ path ));
158+ return $ this ->getWrapperStorage () ->isSharable ($ this ->findPathToUse ($ path ));
159159 }
160160
161161 public function getPermissions (string $ path ): int {
162- return $ this ->storage ->getPermissions ($ this ->findPathToUse ($ path ));
162+ return $ this ->getWrapperStorage () ->getPermissions ($ this ->findPathToUse ($ path ));
163163 }
164164
165165 public function file_exists (string $ path ): bool {
166- return $ this ->storage ->file_exists ($ this ->findPathToUse ($ path ));
166+ return $ this ->getWrapperStorage () ->file_exists ($ this ->findPathToUse ($ path ));
167167 }
168168
169169 public function filemtime (string $ path ): int |false {
170- return $ this ->storage ->filemtime ($ this ->findPathToUse ($ path ));
170+ return $ this ->getWrapperStorage () ->filemtime ($ this ->findPathToUse ($ path ));
171171 }
172172
173173 public function file_get_contents (string $ path ): string |false {
174- return $ this ->storage ->file_get_contents ($ this ->findPathToUse ($ path ));
174+ return $ this ->getWrapperStorage () ->file_get_contents ($ this ->findPathToUse ($ path ));
175175 }
176176
177177 public function file_put_contents (string $ path , mixed $ data ): int |float |false {
178- return $ this ->storage ->file_put_contents ($ this ->findPathToUse ($ path ), $ data );
178+ return $ this ->getWrapperStorage () ->file_put_contents ($ this ->findPathToUse ($ path ), $ data );
179179 }
180180
181181 public function unlink (string $ path ): bool {
182- $ result = $ this ->storage ->unlink ($ this ->findPathToUse ($ path ));
182+ $ result = $ this ->getWrapperStorage () ->unlink ($ this ->findPathToUse ($ path ));
183183 if ($ result ) {
184184 unset($ this ->namesCache [$ path ]);
185185 }
@@ -188,69 +188,69 @@ public function unlink(string $path): bool {
188188
189189 public function rename (string $ source , string $ target ): bool {
190190 // second name always NFC
191- return $ this ->storage ->rename ($ this ->findPathToUse ($ source ), $ this ->findPathToUse ($ target ));
191+ return $ this ->getWrapperStorage () ->rename ($ this ->findPathToUse ($ source ), $ this ->findPathToUse ($ target ));
192192 }
193193
194194 public function copy (string $ source , string $ target ): bool {
195- return $ this ->storage ->copy ($ this ->findPathToUse ($ source ), $ this ->findPathToUse ($ target ));
195+ return $ this ->getWrapperStorage () ->copy ($ this ->findPathToUse ($ source ), $ this ->findPathToUse ($ target ));
196196 }
197197
198198 public function fopen (string $ path , string $ mode ) {
199- $ result = $ this ->storage ->fopen ($ this ->findPathToUse ($ path ), $ mode );
199+ $ result = $ this ->getWrapperStorage () ->fopen ($ this ->findPathToUse ($ path ), $ mode );
200200 if ($ result && $ mode !== 'r ' && $ mode !== 'rb ' ) {
201201 unset($ this ->namesCache [$ path ]);
202202 }
203203 return $ result ;
204204 }
205205
206206 public function getMimeType (string $ path ): string |false {
207- return $ this ->storage ->getMimeType ($ this ->findPathToUse ($ path ));
207+ return $ this ->getWrapperStorage () ->getMimeType ($ this ->findPathToUse ($ path ));
208208 }
209209
210210 public function hash (string $ type , string $ path , bool $ raw = false ): string |false {
211- return $ this ->storage ->hash ($ type , $ this ->findPathToUse ($ path ), $ raw );
211+ return $ this ->getWrapperStorage () ->hash ($ type , $ this ->findPathToUse ($ path ), $ raw );
212212 }
213213
214214 public function free_space (string $ path ): int |float |false {
215- return $ this ->storage ->free_space ($ this ->findPathToUse ($ path ));
215+ return $ this ->getWrapperStorage () ->free_space ($ this ->findPathToUse ($ path ));
216216 }
217217
218218 public function touch (string $ path , ?int $ mtime = null ): bool {
219- return $ this ->storage ->touch ($ this ->findPathToUse ($ path ), $ mtime );
219+ return $ this ->getWrapperStorage () ->touch ($ this ->findPathToUse ($ path ), $ mtime );
220220 }
221221
222222 public function getLocalFile (string $ path ): string |false {
223- return $ this ->storage ->getLocalFile ($ this ->findPathToUse ($ path ));
223+ return $ this ->getWrapperStorage () ->getLocalFile ($ this ->findPathToUse ($ path ));
224224 }
225225
226226 public function hasUpdated (string $ path , int $ time ): bool {
227- return $ this ->storage ->hasUpdated ($ this ->findPathToUse ($ path ), $ time );
227+ return $ this ->getWrapperStorage () ->hasUpdated ($ this ->findPathToUse ($ path ), $ time );
228228 }
229229
230230 public function getCache (string $ path = '' , ?IStorage $ storage = null ): ICache {
231231 if (!$ storage ) {
232232 $ storage = $ this ;
233233 }
234- return $ this ->storage ->getCache ($ this ->findPathToUse ($ path ), $ storage );
234+ return $ this ->getWrapperStorage () ->getCache ($ this ->findPathToUse ($ path ), $ storage );
235235 }
236236
237237 public function getScanner (string $ path = '' , ?IStorage $ storage = null ): IScanner {
238238 if (!$ storage ) {
239239 $ storage = $ this ;
240240 }
241- return $ this ->storage ->getScanner ($ this ->findPathToUse ($ path ), $ storage );
241+ return $ this ->getWrapperStorage () ->getScanner ($ this ->findPathToUse ($ path ), $ storage );
242242 }
243243
244244 public function getETag (string $ path ): string |false {
245- return $ this ->storage ->getETag ($ this ->findPathToUse ($ path ));
245+ return $ this ->getWrapperStorage () ->getETag ($ this ->findPathToUse ($ path ));
246246 }
247247
248248 public function copyFromStorage (IStorage $ sourceStorage , string $ sourceInternalPath , string $ targetInternalPath ): bool {
249249 if ($ sourceStorage === $ this ) {
250250 return $ this ->copy ($ sourceInternalPath , $ this ->findPathToUse ($ targetInternalPath ));
251251 }
252252
253- $ result = $ this ->storage ->copyFromStorage ($ sourceStorage , $ sourceInternalPath , $ this ->findPathToUse ($ targetInternalPath ));
253+ $ result = $ this ->getWrapperStorage () ->copyFromStorage ($ sourceStorage , $ sourceInternalPath , $ this ->findPathToUse ($ targetInternalPath ));
254254 if ($ result ) {
255255 unset($ this ->namesCache [$ targetInternalPath ]);
256256 }
@@ -267,7 +267,7 @@ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalP
267267 return $ result ;
268268 }
269269
270- $ result = $ this ->storage ->moveFromStorage ($ sourceStorage , $ sourceInternalPath , $ this ->findPathToUse ($ targetInternalPath ));
270+ $ result = $ this ->getWrapperStorage () ->moveFromStorage ($ sourceStorage , $ sourceInternalPath , $ this ->findPathToUse ($ targetInternalPath ));
271271 if ($ result ) {
272272 unset($ this ->namesCache [$ sourceInternalPath ]);
273273 unset($ this ->namesCache [$ targetInternalPath ]);
@@ -276,15 +276,15 @@ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalP
276276 }
277277
278278 public function getMetaData (string $ path ): ?array {
279- $ entry = $ this ->storage ->getMetaData ($ this ->findPathToUse ($ path ));
279+ $ entry = $ this ->getWrapperStorage () ->getMetaData ($ this ->findPathToUse ($ path ));
280280 if ($ entry !== null ) {
281281 $ entry ['name ' ] = trim (Filesystem::normalizePath ($ entry ['name ' ]), '/ ' );
282282 }
283283 return $ entry ;
284284 }
285285
286286 public function getDirectoryContent (string $ directory ): \Traversable {
287- $ entries = $ this ->storage ->getDirectoryContent ($ this ->findPathToUse ($ directory ));
287+ $ entries = $ this ->getWrapperStorage () ->getDirectoryContent ($ this ->findPathToUse ($ directory ));
288288 foreach ($ entries as $ entry ) {
289289 $ entry ['name ' ] = trim (Filesystem::normalizePath ($ entry ['name ' ]), '/ ' );
290290 yield $ entry ;
0 commit comments