Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
37 / 37
100.00% covered (success)
100.00%
33 / 33
CRAP
100.00% covered (success)
100.00%
1 / 1
Storage
100.00% covered (success)
100.00%
37 / 37
100.00% covered (success)
100.00%
33 / 33
35
100.00% covered (success)
100.00%
1 / 1
 createLocal
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createS3
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createAzure
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 setBaseDir
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getBaseDir
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCurrentDir
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 chdir
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 mkdir
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 rmdir
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 listAll
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 listDirs
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 listFiles
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 putFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 putFileContents
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 uploadFiles
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 uploadFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 copyFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 copyFileToExternal
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 copyFileFromExternal
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 moveFileToExternal
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 moveFileFromExternal
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 renameFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 replaceFileContents
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 deleteFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fetchFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fetchFileInfo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fileExists
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isDir
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFileSize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFileType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFileMTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 md5File
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Storage;
15
16use Aws\S3\S3Client;
17
18/**
19 * Storage  class
20 *
21 * @category   Pop
22 * @package    Pop\Storage
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    2.0.0
27 */
28class Storage extends AbstractStorage
29{
30
31    /**
32     * Create storage object with local adapter
33     *
34     * @param  string $directory
35     * @return Storage
36     */
37    public static function createLocal(string $directory): Storage
38    {
39        return new self(new Adapter\Local($directory));
40    }
41
42    /**
43     * Create storage object with S3 adapter
44     *
45     * @param  string   $directory
46     * @param  S3Client $client
47     * @return Storage
48     */
49    public static function createS3(string $directory, S3Client $client): Storage
50    {
51        return new self(new Adapter\S3($directory, $client));
52    }
53
54    /**
55     * Create storage object with S3 adapter
56     *
57     * @param  string $accountName
58     * @param  string $accountKey
59     * @param  ?string $container
60     * @throws \Pop\Http\Client\Exception
61     * @return Storage
62     */
63    public static function createAzure(string $accountName, string $accountKey, ?string $container = null): Storage
64    {
65        $azure = new self(Adapter\Azure::create($accountName, $accountKey));
66        if ($container != null) {
67            $azure->chdir($container);
68        }
69        return $azure;
70    }
71
72    /**
73     * Set base directory
74     *
75     * @param  ?string $directory
76     * @return void
77     */
78    public function setBaseDir(?string $directory = null): void
79    {
80        $this->adapter->setBaseDir($directory);
81    }
82
83    /**
84     * Get base directory
85     *
86     * @return ?string
87     */
88    public function getBaseDir(): ?string
89    {
90        return $this->adapter->getBaseDir();
91    }
92
93    /**
94     * Get current directory
95     *
96     * @return ?string
97     */
98    public function getCurrentDir(): ?string
99    {
100        return $this->adapter->getCurrentDir();
101    }
102
103    /**
104     * Change directory
105     *
106     * @param  ?string $directory
107     * @return void
108     */
109    public function chdir(?string $directory = null): void
110    {
111        $this->adapter->chdir($directory);
112    }
113
114    /**
115     * Make directory
116     *
117     * @param  string $directory
118     * @return void
119     */
120    public function mkdir(string $directory): void
121    {
122        $this->adapter->mkdir($directory);
123    }
124
125    /**
126     * Remove a directory
127     *
128     * @param  string $directory
129     * @return void
130     */
131    public function rmdir(string $directory): void
132    {
133        $this->adapter->rmdir($directory);
134    }
135
136    /**
137     * List all
138     *
139     * @param  ?string $search
140     * @return array
141     */
142    public function listAll(?string $search = null): array
143    {
144        return $this->adapter->listAll($search);
145    }
146
147    /**
148     * List directories
149     *
150     * @param  ?string $search
151     * @return array
152     */
153    public function listDirs(?string $search = null): array
154    {
155        return $this->adapter->listDirs($search);
156    }
157
158    /**
159     * List files
160     *
161     * @param  ?string $search
162     * @return array
163     */
164    public function listFiles(?string $search = null): array
165    {
166        return $this->adapter->listFiles($search);
167    }
168
169    /**
170     * Put file
171     *
172     * @param  string $fileFrom
173     * @param  bool   $copy
174     * @return void
175     */
176    public function putFile(string $fileFrom, bool $copy = true): void
177    {
178        $this->adapter->putFile($fileFrom, $copy);
179    }
180
181    /**
182     * Put file contents
183     *
184     * @param  string $filename
185     * @param  string $fileContents
186     * @return void
187     */
188    public function putFileContents(string $filename, string $fileContents): void
189    {
190        $this->adapter->putFileContents($filename, $fileContents);
191    }
192
193    /**
194     * Upload files from server request $_FILES
195     *
196     * @param  array $files
197     * @return void
198     */
199    public function uploadFiles(array $files): void
200    {
201        foreach ($files as $file) {
202            $this->adapter->uploadFile($file);
203        }
204    }
205
206    /**
207     * Upload file from server request $_FILES['file']
208     *
209     * @param  array $file
210     * @return void
211     */
212    public function uploadFile(array $file): void
213    {
214        $this->adapter->uploadFile($file);
215    }
216
217    /**
218     * Copy file
219     *
220     * @param  string $sourceFile
221     * @param  string $destFile
222     * @return void
223     */
224    public function copyFile(string $sourceFile, string $destFile): void
225    {
226        $this->adapter->copyFile($sourceFile, $destFile);
227    }
228
229    /**
230     * Copy file to a location external to the current location
231     *
232     * @param  string $sourceFile
233     * @param  string $externalFile
234     * @return void
235     */
236    public function copyFileToExternal(string $sourceFile, string $externalFile): void
237    {
238        $this->adapter->copyFileToExternal($sourceFile, $externalFile);
239    }
240
241    /**
242     * Copy file from a location external to the current location
243     *
244     * @param  string $externalFile
245     * @param  string $destFile
246     * @return void
247     */
248    public function copyFileFromExternal(string $externalFile, string $destFile): void
249    {
250        $this->adapter->copyFileFromExternal($externalFile, $destFile);
251    }
252
253    /**
254     * Move file to a location external to the current location
255     *
256     * @param  string $sourceFile
257     * @param  string $externalFile
258     * @return void
259     */
260    public function moveFileToExternal(string $sourceFile, string $externalFile): void
261    {
262        $this->adapter->moveFileToExternal($sourceFile, $externalFile);
263    }
264
265    /**
266     * Move file from a location external to the current location
267     *
268     * @param  string $externalFile
269     * @param  string $destFile
270     * @return void
271     */
272    public function moveFileFromExternal(string $externalFile, string $destFile): void
273    {
274        $this->adapter->moveFileFromExternal($externalFile, $destFile);
275    }
276
277    /**
278     * Rename file
279     *
280     * @param  string $oldFile
281     * @param  string $newFile
282     * @return void
283     */
284    public function renameFile(string $oldFile, string $newFile): void
285    {
286        $this->adapter->renameFile($oldFile, $newFile);
287    }
288
289    /**
290     * Replace file
291     *
292     * @param  string $filename
293     * @param  string $fileContents
294     * @return void
295     */
296    public function replaceFileContents(string $filename, string $fileContents): void
297    {
298        $this->adapter->replaceFileContents($filename, $fileContents);
299    }
300
301    /**
302     * Delete file
303     *
304     * @param  string $filename
305     * @return void
306     */
307    public function deleteFile(string $filename): void
308    {
309        $this->adapter->deleteFile($filename);
310    }
311
312    /**
313     * Fetch file contents
314     *
315     * @param  string $filename
316     * @return mixed
317     */
318    public function fetchFile(string $filename): mixed
319    {
320        return $this->adapter->fetchFile($filename);
321    }
322
323    /**
324     * Fetch file info
325     *
326     * @param  string $filename
327     * @return array
328     */
329    public function fetchFileInfo(string $filename): array
330    {
331        return $this->adapter->fetchFileInfo($filename);
332    }
333
334    /**
335     * File exists
336     *
337     * @param  string $filename
338     * @return bool
339     */
340    public function fileExists(string $filename): bool
341    {
342        return $this->adapter->fileExists($filename);
343    }
344
345    /**
346     * Check if is a dir
347     *
348     * @param  string $directory
349     * @return bool
350     */
351    public function isDir(string $directory): bool
352    {
353        return $this->adapter->isDir($directory);
354    }
355
356    /**
357     * Check if is a file
358     *
359     * @param  string $filename
360     * @return bool
361     */
362    public function isFile(string $filename): bool
363    {
364        return $this->adapter->isFile($filename);
365    }
366
367    /**
368     * Get file size
369     *
370     * @param  string $filename
371     * @return int|bool
372     */
373    public function getFileSize(string $filename): int|bool
374    {
375        return $this->adapter->getFileSize($filename);
376    }
377
378    /**
379     * Get file type
380     *
381     * @param  string $filename
382     * @return string|bool
383     */
384    public function getFileType(string $filename): string|bool
385    {
386        return $this->adapter->getFileType($filename);
387    }
388
389    /**
390     * Get file modified time
391     *
392     * @param  string $filename
393     * @return int|string|bool
394     */
395    public function getFileMTime(string $filename): int|string|bool
396    {
397        return $this->adapter->getFileMTime($filename);
398    }
399
400    /**
401     * Create MD5 checksum of the file
402     *
403     * @param  string $filename
404     * @return string|bool
405     */
406    public function md5File(string $filename): string|bool
407    {
408        return $this->adapter->md5File($filename);
409    }
410    
411}