Completed
Push — master ( 0e1444...e11ac2 )
by Thierry
01:50
created

UploadedFile::filename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * UploadedFile.php - This class represents an uploaded file.
5
 *
6
 * @package jaxon-core
7
 * @author Thierry Feuzeu <[email protected]>
8
 * @copyright 2017 Thierry Feuzeu <[email protected]>
9
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
10
 * @link https://github.com/jaxon-php/jaxon-core
11
 */
12
13
namespace Jaxon\Request\Support;
14
15
class UploadedFile
16
{
17
    /**
18
     * The uploaded file type
19
     *
20
     * @var string
21
     */
22
    protected $sType;
23
24
    /**
25
     * The uploaded file name, without the extension and slugified
26
     *
27
     * @var string
28
     */
29
    protected $sName;
30
31
    /**
32
     * The uploaded file name, with the extension
33
     *
34
     * @var string
35
     */
36
    protected $sFilename;
37
38
    /**
39
     * The uploaded file path
40
     *
41
     * @var string
42
     */
43
    protected $sPath;
44
45
    /**
46
     * The uploaded file size
47
     *
48
     * @var string
49
     */
50
    protected $sSize;
51
52
    /**
53
     * The uploaded file extension
54
     *
55
     * @var string
56
     */
57
    protected $sExtension;
58
59
    public function __construct($sUploadDir, array $aFile)
60
    {
61
        $this->sType = $aFile['type'];
62
        $this->sName = $this->slugify($aFile['filename']);
63
        $this->sFilename = $aFile['name'];
64
        $this->sExtension = $aFile['extension'];
65
        $this->sSize = $aFile['size'];
66
        $this->sPath = $sUploadDir . $this->sName . '.' . $this->sExtension;
67
    }
68
69
    /**
70
     * Slugify a text
71
     *
72
     * @var string
73
     */
74
    protected function slugify($sText)
75
    {
76
        // Todo: slugify the text.
77
        return $sText;
78
    }
79
80
    /**
81
     * Get the uploaded file type
82
     *
83
     * @return string
84
     */
85
    public function type()
86
    {
87
        return $this->sType;
88
    }
89
90
    /**
91
     * Get the uploaded file name, without the extension and slugified
92
     *
93
     * @return string
94
     */
95
    public function name()
96
    {
97
        return $this->sName;
98
    }
99
100
    /**
101
     * Get the uploaded file name, with the extension
102
     *
103
     * @return string
104
     */
105
    public function filename()
106
    {
107
        return $this->sFilename;
108
    }
109
110
    /**
111
     * Get the uploaded file path
112
     *
113
     * @return string
114
     */
115
    public function path()
116
    {
117
        return $this->sPath;
118
    }
119
120
    /**
121
     * Get the uploaded file size
122
     *
123
     * @return string
124
     */
125
    public function size()
126
    {
127
        return $this->sSize;
128
    }
129
    
130
    /**
131
     * Get the uploaded file extension
132
     *
133
     * @return string
134
     */
135
    public function extension()
136
    {
137
        return $this->sExtension;
138
    }
139
}
140