@@ -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 | if (!function_exists('exif_imagetype')) { |
| 102 | 101 | $this->error = 'Function \'exif_imagetype\' Not found. Please enable \'php_exif\' in your php.ini'; |
| 103 | 102 | } |
@@ -134,8 +133,7 @@ discard block |
||
| 134 | 133 | * |
| 135 | 134 | * @return string|bool |
| 136 | 135 | */ |
| 137 | - public function offsetGet($offset) |
|
| 138 | - { |
|
| 136 | + public function offsetGet($offset) { |
|
| 139 | 137 | // return false if $_FILES['key'] isn't found |
| 140 | 138 | if (!isset($this->_files[$offset])) { |
| 141 | 139 | $this->error = sprintf('No file input found with name: (%s)', $offset); |
@@ -160,8 +158,7 @@ discard block |
||
| 160 | 158 | * |
| 161 | 159 | * @return $this |
| 162 | 160 | */ |
| 163 | - public function setDimension($maxWidth, $maxHeight) |
|
| 164 | - { |
|
| 161 | + public function setDimension($maxWidth, $maxHeight) { |
|
| 165 | 162 | if ( (int) $maxWidth && (int) $maxHeight) { |
| 166 | 163 | $this->dimensions = array($maxWidth, $maxHeight); |
| 167 | 164 | } else { |
@@ -176,8 +173,7 @@ discard block |
||
| 176 | 173 | * |
| 177 | 174 | * @return string |
| 178 | 175 | */ |
| 179 | - public function getFullPath() |
|
| 180 | - { |
|
| 176 | + public function getFullPath() { |
|
| 181 | 177 | return $this->fullPath = $this->getLocation().'/'.$this->getName().'.'.$this->getMime(); |
| 182 | 178 | } |
| 183 | 179 | |
@@ -186,8 +182,7 @@ discard block |
||
| 186 | 182 | * |
| 187 | 183 | * @return int |
| 188 | 184 | */ |
| 189 | - public function getSize() |
|
| 190 | - { |
|
| 185 | + public function getSize() { |
|
| 191 | 186 | return (int) $this->_files['size']; |
| 192 | 187 | } |
| 193 | 188 | |
@@ -199,8 +194,7 @@ discard block |
||
| 199 | 194 | * |
| 200 | 195 | * @return $this |
| 201 | 196 | */ |
| 202 | - public function setSize($min, $max) |
|
| 203 | - { |
|
| 197 | + public function setSize($min, $max) { |
|
| 204 | 198 | $this->size = array($min, $max); |
| 205 | 199 | return $this; |
| 206 | 200 | } |
@@ -210,8 +204,7 @@ discard block |
||
| 210 | 204 | * |
| 211 | 205 | * @return string |
| 212 | 206 | */ |
| 213 | - public function getJson() |
|
| 214 | - { |
|
| 207 | + public function getJson() { |
|
| 215 | 208 | return json_encode( |
| 216 | 209 | array( |
| 217 | 210 | 'name' => $this->name, |
@@ -230,8 +223,7 @@ discard block |
||
| 230 | 223 | * |
| 231 | 224 | * @return null|string |
| 232 | 225 | */ |
| 233 | - public function getMime() |
|
| 234 | - { |
|
| 226 | + public function getMime() { |
|
| 235 | 227 | if (!$this->mime) { |
| 236 | 228 | $this->mime = $this->getImageMime($this->_files['tmp_name']); |
| 237 | 229 | } |
@@ -246,8 +238,7 @@ discard block |
||
| 246 | 238 | * |
| 247 | 239 | * @return $this |
| 248 | 240 | */ |
| 249 | - public function setMime(array $fileTypes) |
|
| 250 | - { |
|
| 241 | + public function setMime(array $fileTypes) { |
|
| 251 | 242 | $this->mimeTypes = $fileTypes; |
| 252 | 243 | return $this; |
| 253 | 244 | } |
@@ -259,8 +250,7 @@ discard block |
||
| 259 | 250 | * |
| 260 | 251 | * @return null|string |
| 261 | 252 | */ |
| 262 | - protected function getImageMime($tmp_name) |
|
| 263 | - { |
|
| 253 | + protected function getImageMime($tmp_name) { |
|
| 264 | 254 | $this->mime = @$this->acceptedMimes[exif_imagetype($tmp_name)]; |
| 265 | 255 | if (!$this->mime) { |
| 266 | 256 | return null; |
@@ -274,8 +264,7 @@ discard block |
||
| 274 | 264 | * |
| 275 | 265 | * @return string|false |
| 276 | 266 | */ |
| 277 | - public function getError() |
|
| 278 | - { |
|
| 267 | + public function getError() { |
|
| 279 | 268 | return $this->error; |
| 280 | 269 | } |
| 281 | 270 | |
@@ -284,8 +273,7 @@ discard block |
||
| 284 | 273 | * |
| 285 | 274 | * @return string |
| 286 | 275 | */ |
| 287 | - public function getName() |
|
| 288 | - { |
|
| 276 | + public function getName() { |
|
| 289 | 277 | if (!$this->name) { |
| 290 | 278 | $this->name = uniqid('', true).'_'.str_shuffle(implode(range('e', 'q'))); |
| 291 | 279 | } |
@@ -300,8 +288,7 @@ discard block |
||
| 300 | 288 | * |
| 301 | 289 | * @return $this |
| 302 | 290 | */ |
| 303 | - public function setName($isNameProvided = null) |
|
| 304 | - { |
|
| 291 | + public function setName($isNameProvided = null) { |
|
| 305 | 292 | if ($isNameProvided) { |
| 306 | 293 | $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING); |
| 307 | 294 | } |
@@ -314,8 +301,7 @@ discard block |
||
| 314 | 301 | * |
| 315 | 302 | * @return int |
| 316 | 303 | */ |
| 317 | - public function getWidth() |
|
| 318 | - { |
|
| 304 | + public function getWidth() { |
|
| 319 | 305 | if ($this->width != null) { |
| 320 | 306 | return $this->width; |
| 321 | 307 | } |
@@ -330,8 +316,7 @@ discard block |
||
| 330 | 316 | * |
| 331 | 317 | * @return int |
| 332 | 318 | */ |
| 333 | - public function getHeight() |
|
| 334 | - { |
|
| 319 | + public function getHeight() { |
|
| 335 | 320 | if ($this->height != null) { |
| 336 | 321 | return $this->height; |
| 337 | 322 | } |
@@ -346,8 +331,7 @@ discard block |
||
| 346 | 331 | * |
| 347 | 332 | * @return string |
| 348 | 333 | */ |
| 349 | - public function getLocation() |
|
| 350 | - { |
|
| 334 | + public function getLocation() { |
|
| 351 | 335 | if (!$this->location) { |
| 352 | 336 | $this->setLocation(); |
| 353 | 337 | } |
@@ -362,8 +346,7 @@ discard block |
||
| 362 | 346 | * |
| 363 | 347 | * @return bool |
| 364 | 348 | */ |
| 365 | - private function isDirectoryValid($dir) |
|
| 366 | - { |
|
| 349 | + private function isDirectoryValid($dir) { |
|
| 367 | 350 | return !file_exists($dir) && !is_dir($dir) || is_writable($dir); |
| 368 | 351 | } |
| 369 | 352 | |
@@ -375,8 +358,7 @@ discard block |
||
| 375 | 358 | * |
| 376 | 359 | * @return $this |
| 377 | 360 | */ |
| 378 | - public function setLocation($dir = 'bulletproof', $permission = 0666) |
|
| 379 | - { |
|
| 361 | + public function setLocation($dir = 'bulletproof', $permission = 0666) { |
|
| 380 | 362 | $isDirectoryValid = $this->isDirectoryValid($dir); |
| 381 | 363 | |
| 382 | 364 | if (!$isDirectoryValid) { |
@@ -401,8 +383,7 @@ discard block |
||
| 401 | 383 | * |
| 402 | 384 | * @return boolean |
| 403 | 385 | */ |
| 404 | - protected function contraintsValidator() |
|
| 405 | - { |
|
| 386 | + protected function contraintsValidator() { |
|
| 406 | 387 | /* check image for valid mime types and return mime */ |
| 407 | 388 | $this->getImageMime($this->_files['tmp_name']); |
| 408 | 389 | /* validate image mime type */ |
@@ -440,8 +421,7 @@ discard block |
||
| 440 | 421 | * |
| 441 | 422 | * @return false|Image |
| 442 | 423 | */ |
| 443 | - public function upload() |
|
| 444 | - { |
|
| 424 | + public function upload() { |
|
| 445 | 425 | if ($this->error) { |
| 446 | 426 | return false; |
| 447 | 427 | } |
@@ -461,8 +441,7 @@ discard block |
||
| 461 | 441 | * |
| 462 | 442 | * @return bool |
| 463 | 443 | */ |
| 464 | - protected function isSaved($tmp_name, $destination) |
|
| 465 | - { |
|
| 444 | + protected function isSaved($tmp_name, $destination) { |
|
| 466 | 445 | return move_uploaded_file($tmp_name, $destination); |
| 467 | 446 | } |
| 468 | 447 | } |
| 469 | 448 | \ No newline at end of file |