@@ -15,36 +15,36 @@ |
||
15 | 15 | interface FileSubmissionInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @return string |
|
20 | - */ |
|
21 | - public function getName(); |
|
22 | - |
|
23 | - /** |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function getType(); |
|
27 | - |
|
28 | - /** |
|
29 | - * @return int |
|
30 | - */ |
|
31 | - public function getSize(); |
|
32 | - |
|
33 | - /** |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public function getTmpFile(); |
|
37 | - |
|
38 | - /** |
|
39 | - * @since $VID:$ |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function __toString(); |
|
43 | - |
|
44 | - /** |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function getErrorCode(); |
|
18 | + /** |
|
19 | + * @return string |
|
20 | + */ |
|
21 | + public function getName(); |
|
22 | + |
|
23 | + /** |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function getType(); |
|
27 | + |
|
28 | + /** |
|
29 | + * @return int |
|
30 | + */ |
|
31 | + public function getSize(); |
|
32 | + |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public function getTmpFile(); |
|
37 | + |
|
38 | + /** |
|
39 | + * @since $VID:$ |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function __toString(); |
|
43 | + |
|
44 | + /** |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function getErrorCode(); |
|
48 | 48 | } |
49 | 49 | // End of file FileSubmissionInterface.php |
50 | 50 | // Location: EventEspresso\core\services\request\files/FileSubmissionInterface.php |
@@ -19,158 +19,158 @@ |
||
19 | 19 | */ |
20 | 20 | class FileSubmission implements FileSubmissionInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * @var string original name on the client machine |
|
24 | - */ |
|
25 | - protected $name; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var string mime type |
|
29 | - */ |
|
30 | - protected $type; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string file extension |
|
34 | - */ |
|
35 | - protected $extension; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var int in bytes |
|
39 | - */ |
|
40 | - protected $size; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var string local filepath to the temporary file |
|
44 | - */ |
|
45 | - protected $tmp_file; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var int one of UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE or other values |
|
49 | - * although those aren't expected. |
|
50 | - */ |
|
51 | - protected $error_code; |
|
52 | - |
|
53 | - /** |
|
54 | - * FileSubmission constructor. |
|
55 | - * @param $name |
|
56 | - * @param $tmp_file |
|
57 | - * @param $size |
|
58 | - * @param null $error_code |
|
59 | - * @throws InvalidArgumentException |
|
60 | - */ |
|
61 | - public function __construct($name, $tmp_file, $size, $error_code = null) |
|
62 | - { |
|
63 | - $this->name = basename($name); |
|
64 | - if (parse_url($tmp_file, PHP_URL_SCHEME)) { |
|
65 | - // Wait a minute- just local filepaths please, no URL schemes allowed! |
|
66 | - throw new InvalidArgumentException( |
|
67 | - sprintf( |
|
68 | - // @codingStandardsIgnoreStart |
|
69 | - esc_html__('The filepath of the temporary file ("%1$s") indicates is located elsewhere, that’s not ok!', 'event_espresso'), |
|
70 | - // @codingStandardsIgnoreEnd |
|
71 | - $tmp_file |
|
72 | - ) |
|
73 | - ); |
|
74 | - } |
|
75 | - $this->tmp_file = (string) $tmp_file; |
|
76 | - $this->size = (int) $size; |
|
77 | - $this->error_code = (int) $error_code; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function getName() |
|
84 | - { |
|
85 | - return $this->name; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Gets the file's mime type |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function getType() |
|
93 | - { |
|
94 | - if (!$this->type) { |
|
95 | - $this->type = $this->determineType(); |
|
96 | - } |
|
97 | - return $this->type; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @since $VID:$ |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - protected function determineType() |
|
105 | - { |
|
106 | - if (!$this->getTmpFile()) { |
|
107 | - return ''; |
|
108 | - } |
|
109 | - $finfo = new finfo(FILEINFO_MIME_TYPE); |
|
110 | - return $finfo->file($this->getTmpFile()); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Gets the file's extension. |
|
115 | - * @since $VID:$ |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - public function getExtension() |
|
119 | - { |
|
120 | - if (!$this->extension) { |
|
121 | - $this->extension = $this->determineExtension(); |
|
122 | - } |
|
123 | - return $this->extension; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Determine's the file's extension given the temporary file. |
|
128 | - * @since $VID:$ |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - protected function determineExtension() |
|
132 | - { |
|
133 | - if (!$this->getTmpFile()) { |
|
134 | - return ''; |
|
135 | - } |
|
136 | - return pathinfo($this->getTmpFile(), PATHINFO_EXTENSION); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Gets the size of the file |
|
141 | - * @return int |
|
142 | - */ |
|
143 | - public function getSize() |
|
144 | - { |
|
145 | - return $this->size; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Gets the path to the temporary file which was uploaded. |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - public function getTmpFile() |
|
153 | - { |
|
154 | - return $this->tmp_file; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @since $VID:$ |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function __toString() |
|
162 | - { |
|
163 | - return $this->getTmpFile(); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Gets the error code PHP reported for the file upload. |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function getErrorCode() |
|
171 | - { |
|
172 | - return $this->error_code; |
|
173 | - } |
|
22 | + /** |
|
23 | + * @var string original name on the client machine |
|
24 | + */ |
|
25 | + protected $name; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var string mime type |
|
29 | + */ |
|
30 | + protected $type; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string file extension |
|
34 | + */ |
|
35 | + protected $extension; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var int in bytes |
|
39 | + */ |
|
40 | + protected $size; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var string local filepath to the temporary file |
|
44 | + */ |
|
45 | + protected $tmp_file; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var int one of UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE or other values |
|
49 | + * although those aren't expected. |
|
50 | + */ |
|
51 | + protected $error_code; |
|
52 | + |
|
53 | + /** |
|
54 | + * FileSubmission constructor. |
|
55 | + * @param $name |
|
56 | + * @param $tmp_file |
|
57 | + * @param $size |
|
58 | + * @param null $error_code |
|
59 | + * @throws InvalidArgumentException |
|
60 | + */ |
|
61 | + public function __construct($name, $tmp_file, $size, $error_code = null) |
|
62 | + { |
|
63 | + $this->name = basename($name); |
|
64 | + if (parse_url($tmp_file, PHP_URL_SCHEME)) { |
|
65 | + // Wait a minute- just local filepaths please, no URL schemes allowed! |
|
66 | + throw new InvalidArgumentException( |
|
67 | + sprintf( |
|
68 | + // @codingStandardsIgnoreStart |
|
69 | + esc_html__('The filepath of the temporary file ("%1$s") indicates is located elsewhere, that’s not ok!', 'event_espresso'), |
|
70 | + // @codingStandardsIgnoreEnd |
|
71 | + $tmp_file |
|
72 | + ) |
|
73 | + ); |
|
74 | + } |
|
75 | + $this->tmp_file = (string) $tmp_file; |
|
76 | + $this->size = (int) $size; |
|
77 | + $this->error_code = (int) $error_code; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function getName() |
|
84 | + { |
|
85 | + return $this->name; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Gets the file's mime type |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function getType() |
|
93 | + { |
|
94 | + if (!$this->type) { |
|
95 | + $this->type = $this->determineType(); |
|
96 | + } |
|
97 | + return $this->type; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @since $VID:$ |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + protected function determineType() |
|
105 | + { |
|
106 | + if (!$this->getTmpFile()) { |
|
107 | + return ''; |
|
108 | + } |
|
109 | + $finfo = new finfo(FILEINFO_MIME_TYPE); |
|
110 | + return $finfo->file($this->getTmpFile()); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Gets the file's extension. |
|
115 | + * @since $VID:$ |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + public function getExtension() |
|
119 | + { |
|
120 | + if (!$this->extension) { |
|
121 | + $this->extension = $this->determineExtension(); |
|
122 | + } |
|
123 | + return $this->extension; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Determine's the file's extension given the temporary file. |
|
128 | + * @since $VID:$ |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + protected function determineExtension() |
|
132 | + { |
|
133 | + if (!$this->getTmpFile()) { |
|
134 | + return ''; |
|
135 | + } |
|
136 | + return pathinfo($this->getTmpFile(), PATHINFO_EXTENSION); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Gets the size of the file |
|
141 | + * @return int |
|
142 | + */ |
|
143 | + public function getSize() |
|
144 | + { |
|
145 | + return $this->size; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Gets the path to the temporary file which was uploaded. |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + public function getTmpFile() |
|
153 | + { |
|
154 | + return $this->tmp_file; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @since $VID:$ |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function __toString() |
|
162 | + { |
|
163 | + return $this->getTmpFile(); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Gets the error code PHP reported for the file upload. |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function getErrorCode() |
|
171 | + { |
|
172 | + return $this->error_code; |
|
173 | + } |
|
174 | 174 | } |
175 | 175 | // End of file FileSubmission.php |
176 | 176 | // Location: EventEspresso\core\services\request\files/FileSubmission.php |