Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
Local
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
5 / 5
7
100.00% covered (success)
100.00%
1 / 1
 uploadFile
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 uploadFileStream
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 rmdir
100.00% covered (success)
100.00%
2 / 2
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
 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-2023 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 Pop\Dir\Dir;
17use Pop\Http\Server\Upload;
18
19/**
20 * Local storage adapter class
21 *
22 * @category   Pop
23 * @package    Pop\Storage
24 * @author     Nick Sagona, III <dev@nolainteractive.com>
25 * @copyright  Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
26 * @license    http://www.popphp.org/license     New BSD License
27 * @version    1.0.0
28 */
29class Local extends AbstractAdapter
30{
31
32    /**
33     * Is local flag
34     * @var boolean
35     */
36    protected $local = true;
37
38    /**
39     * Upload file
40     *
41     * @param  mixed   $file
42     * @param  string  $dest
43     * @param  Upload  $upload
44     * @param  boolean $secure
45     * @return string
46     */
47    public function uploadFile($file, $dest = null, Upload $upload = null, $secure = true)
48    {
49        if (!is_array($file)) {
50            throw new Exception('Error: The file parameter must be an array.');
51        }
52        return $upload->upload($file, $dest, $secure);
53    }
54
55    /**
56     * Upload file stream
57     *
58     * @param  string  $fileStream
59     * @param  string  $filename
60     * @param  string  $folder
61     * @return string
62     */
63    public function uploadFileStream($fileStream, $filename, $folder = null)
64    {
65        if (!file_exists($this->location . $folder)) {
66            $this->mkdir($folder);
67        }
68        $location = $this->location . $folder . '/' . $filename;
69        file_put_contents($location, $fileStream);
70        return $filename;
71    }
72
73    /**
74     * Remove a directory
75     *
76     * @param  string $dir
77     * @return void
78     */
79    public function rmdir($dir)
80    {
81        $dir = new Dir($this->location . $dir);
82        $dir->emptyDir(true);
83    }
84
85    /**
86     * Make a directory
87     *
88     * @param  string $dir
89     * @return void
90     */
91    public function mkdir($dir)
92    {
93        mkdir($this->location . $dir);
94    }
95
96    /**
97     * Create MD5 checksum of the file
98     *
99     * @param  string $filename
100     * @return string
101     */
102    public function md5File($filename)
103    {
104        return md5_file($this->checkFileLocation($filename));
105    }
106
107}