@@ -96,8 +96,7 @@ discard block |
||
96 | 96 | /** |
97 | 97 | * @param array $_files represents the $_FILES array passed as dependency |
98 | 98 | */ |
99 | - public function __construct(array $_files = array()) |
|
100 | - { |
|
99 | + public function __construct(array $_files = array()) { |
|
101 | 100 | /* check if php_exif is enabled */ |
102 | 101 | if (!function_exists('exif_imagetype')) { |
103 | 102 | $this->error = 'Function \'exif_imagetype\' Not found. Please enable \'php_exif\' in your PHP.ini'; |
@@ -136,8 +135,7 @@ discard block |
||
136 | 135 | * |
137 | 136 | * @return string|bool |
138 | 137 | */ |
139 | - public function offsetGet($offset) |
|
140 | - { |
|
138 | + public function offsetGet($offset) { |
|
141 | 139 | /* return false if $image['key'] isn't found */ |
142 | 140 | if (!isset($this->_files[$offset])) { |
143 | 141 | $this->error = sprintf('No file input found with name: (%s)', $offset); |
@@ -163,8 +161,7 @@ discard block |
||
163 | 161 | * |
164 | 162 | * @return $this |
165 | 163 | */ |
166 | - public function setDimension($maxWidth, $maxHeight) |
|
167 | - { |
|
164 | + public function setDimension($maxWidth, $maxHeight) { |
|
168 | 165 | $this->dimensions = array($maxWidth, $maxHeight); |
169 | 166 | |
170 | 167 | return $this; |
@@ -175,8 +172,7 @@ discard block |
||
175 | 172 | * |
176 | 173 | * @return string |
177 | 174 | */ |
178 | - public function getPath() |
|
179 | - { |
|
175 | + public function getPath() { |
|
180 | 176 | return $this->path = $this->getStorage() . '/' . $this->getName() . '.' . $this->getMime(); |
181 | 177 | } |
182 | 178 | |
@@ -185,8 +181,7 @@ discard block |
||
185 | 181 | * |
186 | 182 | * @return int |
187 | 183 | */ |
188 | - public function getSize() |
|
189 | - { |
|
184 | + public function getSize() { |
|
190 | 185 | return (int) $this->_files['size']; |
191 | 186 | } |
192 | 187 | |
@@ -198,8 +193,7 @@ discard block |
||
198 | 193 | * |
199 | 194 | * @return $this |
200 | 195 | */ |
201 | - public function setSize($min, $max) |
|
202 | - { |
|
196 | + public function setSize($min, $max) { |
|
203 | 197 | $this->size = array($min, $max); |
204 | 198 | return $this; |
205 | 199 | } |
@@ -209,8 +203,7 @@ discard block |
||
209 | 203 | * |
210 | 204 | * @return string |
211 | 205 | */ |
212 | - public function getJson() |
|
213 | - { |
|
206 | + public function getJson() { |
|
214 | 207 | return json_encode( |
215 | 208 | array( |
216 | 209 | 'name' => $this->name, |
@@ -229,8 +222,7 @@ discard block |
||
229 | 222 | * |
230 | 223 | * @return null|string |
231 | 224 | */ |
232 | - public function getMime() |
|
233 | - { |
|
225 | + public function getMime() { |
|
234 | 226 | if (!$this->mime) { |
235 | 227 | $this->mime = $this->getImageMime($this->_files['tmp_name']); |
236 | 228 | } |
@@ -245,8 +237,7 @@ discard block |
||
245 | 237 | * |
246 | 238 | * @return $this |
247 | 239 | */ |
248 | - public function setMime(array $fileTypes) |
|
249 | - { |
|
240 | + public function setMime(array $fileTypes) { |
|
250 | 241 | $this->mimeTypes = $fileTypes; |
251 | 242 | return $this; |
252 | 243 | } |
@@ -258,8 +249,7 @@ discard block |
||
258 | 249 | * |
259 | 250 | * @return null|string |
260 | 251 | */ |
261 | - protected function getImageMime($tmp_name) |
|
262 | - { |
|
252 | + protected function getImageMime($tmp_name) { |
|
263 | 253 | $this->mime = @$this->acceptedMimes[exif_imagetype($tmp_name)]; |
264 | 254 | if (!$this->mime) { |
265 | 255 | return null; |
@@ -273,8 +263,7 @@ discard block |
||
273 | 263 | * |
274 | 264 | * @return string |
275 | 265 | */ |
276 | - public function getError() |
|
277 | - { |
|
266 | + public function getError() { |
|
278 | 267 | return $this->error; |
279 | 268 | } |
280 | 269 | |
@@ -283,8 +272,7 @@ discard block |
||
283 | 272 | * |
284 | 273 | * @return string |
285 | 274 | */ |
286 | - public function getName() |
|
287 | - { |
|
275 | + public function getName() { |
|
288 | 276 | return $this->name; |
289 | 277 | } |
290 | 278 | |
@@ -295,11 +283,10 @@ discard block |
||
295 | 283 | * |
296 | 284 | * @return $this |
297 | 285 | */ |
298 | - public function setName($isNameProvided = null) |
|
299 | - { |
|
286 | + public function setName($isNameProvided = null) { |
|
300 | 287 | if ($isNameProvided) { |
301 | 288 | $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING); |
302 | - }else{ |
|
289 | + } else{ |
|
303 | 290 | $this->name = uniqid('', true) . '_' . str_shuffle(implode(range('e', 'q'))); |
304 | 291 | } |
305 | 292 | |
@@ -311,8 +298,7 @@ discard block |
||
311 | 298 | * |
312 | 299 | * @return int |
313 | 300 | */ |
314 | - public function getWidth() |
|
315 | - { |
|
301 | + public function getWidth() { |
|
316 | 302 | if ($this->width != null) { |
317 | 303 | return $this->width; |
318 | 304 | } |
@@ -327,8 +313,7 @@ discard block |
||
327 | 313 | * |
328 | 314 | * @return int |
329 | 315 | */ |
330 | - public function getHeight() |
|
331 | - { |
|
316 | + public function getHeight() { |
|
332 | 317 | if ($this->height != null) { |
333 | 318 | return $this->height; |
334 | 319 | } |
@@ -343,8 +328,7 @@ discard block |
||
343 | 328 | * |
344 | 329 | * @return string |
345 | 330 | */ |
346 | - public function getStorage() |
|
347 | - { |
|
331 | + public function getStorage() { |
|
348 | 332 | if (!$this->storage) { |
349 | 333 | $this->setStorage(); |
350 | 334 | } |
@@ -359,8 +343,7 @@ discard block |
||
359 | 343 | * |
360 | 344 | * @return bool |
361 | 345 | */ |
362 | - private function isDirectoryValid($dir) |
|
363 | - { |
|
346 | + private function isDirectoryValid($dir) { |
|
364 | 347 | return !file_exists($dir) && !is_dir($dir) || is_writable($dir); |
365 | 348 | } |
366 | 349 | |
@@ -372,8 +355,7 @@ discard block |
||
372 | 355 | * |
373 | 356 | * @return $this |
374 | 357 | */ |
375 | - public function setStorage($dir = 'uploads', $permission = 0666) |
|
376 | - { |
|
358 | + public function setStorage($dir = 'uploads', $permission = 0666) { |
|
377 | 359 | $isDirectoryValid = $this->isDirectoryValid($dir); |
378 | 360 | |
379 | 361 | if (!$isDirectoryValid) { |
@@ -437,8 +419,7 @@ discard block |
||
437 | 419 | * |
438 | 420 | * @return false|Image |
439 | 421 | */ |
440 | - public function upload() |
|
441 | - { |
|
422 | + public function upload() { |
|
442 | 423 | if ($this->error !== '') { |
443 | 424 | return false; |
444 | 425 | } |
@@ -459,8 +440,7 @@ discard block |
||
459 | 440 | * |
460 | 441 | * @return bool |
461 | 442 | */ |
462 | - protected function isSaved($tmp_name, $destination) |
|
463 | - { |
|
443 | + protected function isSaved($tmp_name, $destination) { |
|
464 | 444 | return move_uploaded_file($tmp_name, $destination); |
465 | 445 | } |
466 | 446 | } |
467 | 447 | \ No newline at end of file |