@@ -98,8 +98,7 @@ discard block |
||
| 98 | 98 | /** |
| 99 | 99 | * @param array $_files represents the $_FILES array passed as dependency |
| 100 | 100 | */ |
| 101 | - public function __construct(array $_files = array()) |
|
| 102 | - {
|
|
| 101 | + public function __construct(array $_files = array()) { |
|
| 103 | 102 | /* check if php_exif is enabled */ |
| 104 | 103 | if (!function_exists('exif_imagetype')) {
|
| 105 | 104 | $this->error = 'Function \'exif_imagetype\' Not found. Please enable \'php_exif\' in your php.ini'; |
@@ -136,8 +135,7 @@ discard block |
||
| 136 | 135 | * @param mixed $offset |
| 137 | 136 | * @return string|boolean |
| 138 | 137 | */ |
| 139 | - public function offsetGet($offset) |
|
| 140 | - {
|
|
| 138 | + public function offsetGet($offset) { |
|
| 141 | 139 | |
| 142 | 140 | // return false if $image['key'] isn't found |
| 143 | 141 | if (!isset($this->_files[$offset])) {
|
@@ -163,11 +161,10 @@ 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 | if( (int) $maxWidth && (int) $maxHeight){
|
| 169 | 166 | $this->dimensions = array($maxWidth, $maxHeight); |
| 170 | - }else{
|
|
| 167 | + } else{
|
|
| 171 | 168 | $this->error = 'Invalid dimention! Values must be integers'; |
| 172 | 169 | } |
| 173 | 170 | |
@@ -179,8 +176,7 @@ discard block |
||
| 179 | 176 | * |
| 180 | 177 | * @return string |
| 181 | 178 | */ |
| 182 | - public function getFullPath() |
|
| 183 | - {
|
|
| 179 | + public function getFullPath() { |
|
| 184 | 180 | return $this->fullPath = $this->getLocation() . '/' . $this->getName() . '.' . $this->getMime(); |
| 185 | 181 | } |
| 186 | 182 | |
@@ -189,8 +185,7 @@ discard block |
||
| 189 | 185 | * |
| 190 | 186 | * @return int |
| 191 | 187 | */ |
| 192 | - public function getSize() |
|
| 193 | - {
|
|
| 188 | + public function getSize() { |
|
| 194 | 189 | return (int) $this->_files['size']; |
| 195 | 190 | } |
| 196 | 191 | |
@@ -202,8 +197,7 @@ discard block |
||
| 202 | 197 | * |
| 203 | 198 | * @return $this |
| 204 | 199 | */ |
| 205 | - public function setSize($min, $max) |
|
| 206 | - {
|
|
| 200 | + public function setSize($min, $max) { |
|
| 207 | 201 | $this->size = array($min, $max); |
| 208 | 202 | return $this; |
| 209 | 203 | } |
@@ -213,8 +207,7 @@ discard block |
||
| 213 | 207 | * |
| 214 | 208 | * @return string |
| 215 | 209 | */ |
| 216 | - public function getJson() |
|
| 217 | - {
|
|
| 210 | + public function getJson() { |
|
| 218 | 211 | return json_encode ( |
| 219 | 212 | array( |
| 220 | 213 | 'name' => $this->name, |
@@ -233,8 +226,7 @@ discard block |
||
| 233 | 226 | * |
| 234 | 227 | * @return null|string |
| 235 | 228 | */ |
| 236 | - public function getMime() |
|
| 237 | - {
|
|
| 229 | + public function getMime() { |
|
| 238 | 230 | if(!$this->mime){
|
| 239 | 231 | $this->mime = $this->getImageMime($this->_files['tmp_name']); |
| 240 | 232 | } |
@@ -249,8 +241,7 @@ discard block |
||
| 249 | 241 | * |
| 250 | 242 | * @return $this |
| 251 | 243 | */ |
| 252 | - public function setMime(array $fileTypes) |
|
| 253 | - {
|
|
| 244 | + public function setMime(array $fileTypes) { |
|
| 254 | 245 | $this->mimeTypes = $fileTypes; |
| 255 | 246 | return $this; |
| 256 | 247 | } |
@@ -262,8 +253,7 @@ discard block |
||
| 262 | 253 | * |
| 263 | 254 | * @return null|string |
| 264 | 255 | */ |
| 265 | - protected function getImageMime($tmp_name) |
|
| 266 | - {
|
|
| 256 | + protected function getImageMime($tmp_name) { |
|
| 267 | 257 | $this->mime = @$this->acceptedMimes[exif_imagetype($tmp_name)]; |
| 268 | 258 | if (!$this->mime) {
|
| 269 | 259 | return null; |
@@ -277,8 +267,7 @@ discard block |
||
| 277 | 267 | * |
| 278 | 268 | * @return string|false |
| 279 | 269 | */ |
| 280 | - public function getError() |
|
| 281 | - {
|
|
| 270 | + public function getError() { |
|
| 282 | 271 | return $this->error; |
| 283 | 272 | } |
| 284 | 273 | |
@@ -287,8 +276,7 @@ discard block |
||
| 287 | 276 | * |
| 288 | 277 | * @return string |
| 289 | 278 | */ |
| 290 | - public function getName() |
|
| 291 | - {
|
|
| 279 | + public function getName() { |
|
| 292 | 280 | if (!$this->name) {
|
| 293 | 281 | $this->name = uniqid('', true) . '_' . str_shuffle(implode(range('e', 'q')));
|
| 294 | 282 | } |
@@ -302,8 +290,7 @@ discard block |
||
| 302 | 290 | * @param null $isNameProvided |
| 303 | 291 | * @return $this |
| 304 | 292 | */ |
| 305 | - public function setName($isNameProvided = null) |
|
| 306 | - {
|
|
| 293 | + public function setName($isNameProvided = null) { |
|
| 307 | 294 | if ($isNameProvided) {
|
| 308 | 295 | $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING); |
| 309 | 296 | } |
@@ -316,8 +303,7 @@ discard block |
||
| 316 | 303 | * |
| 317 | 304 | * @return int |
| 318 | 305 | */ |
| 319 | - public function getWidth() |
|
| 320 | - {
|
|
| 306 | + public function getWidth() { |
|
| 321 | 307 | if ($this->width != null) {
|
| 322 | 308 | return $this->width; |
| 323 | 309 | } |
@@ -331,8 +317,7 @@ discard block |
||
| 331 | 317 | * |
| 332 | 318 | * @return int |
| 333 | 319 | */ |
| 334 | - public function getHeight() |
|
| 335 | - {
|
|
| 320 | + public function getHeight() { |
|
| 336 | 321 | if ($this->height != null) {
|
| 337 | 322 | return $this->height; |
| 338 | 323 | } |
@@ -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 | } |
@@ -361,8 +345,7 @@ discard block |
||
| 361 | 345 | * @param $dir string the folder name to check |
| 362 | 346 | * @return bool |
| 363 | 347 | */ |
| 364 | - private function isDirectoryValid($dir) |
|
| 365 | - {
|
|
| 348 | + private function isDirectoryValid($dir) { |
|
| 366 | 349 | return !file_exists($dir) && !is_dir($dir) || is_writable($dir); |
| 367 | 350 | } |
| 368 | 351 | |
@@ -373,8 +356,7 @@ discard block |
||
| 373 | 356 | * @param int $permission chmod permission |
| 374 | 357 | * @return $this |
| 375 | 358 | */ |
| 376 | - public function setLocation($dir = 'bulletproof', $permission = 0666) |
|
| 377 | - {
|
|
| 359 | + public function setLocation($dir = 'bulletproof', $permission = 0666) { |
|
| 378 | 360 | $isDirectoryValid = $this->isDirectoryValid($dir); |
| 379 | 361 | |
| 380 | 362 | if(!$isDirectoryValid){
|
@@ -399,8 +381,7 @@ discard block |
||
| 399 | 381 | * |
| 400 | 382 | * @return false|Image |
| 401 | 383 | */ |
| 402 | - public function upload() |
|
| 403 | - {
|
|
| 384 | + public function upload() { |
|
| 404 | 385 | $image = $this; |
| 405 | 386 | $files = $this->_files; |
| 406 | 387 | |
@@ -454,8 +435,7 @@ discard block |
||
| 454 | 435 | * |
| 455 | 436 | * @return bool |
| 456 | 437 | */ |
| 457 | - protected function isSaved($tmp_name, $destination) |
|
| 458 | - {
|
|
| 438 | + protected function isSaved($tmp_name, $destination) { |
|
| 459 | 439 | return move_uploaded_file($tmp_name, $destination); |
| 460 | 440 | } |
| 461 | 441 | } |
| 462 | 442 | \ No newline at end of file |