Skip to content

Commit

Permalink
2017-02-25 1547
Browse files Browse the repository at this point in the history
  • Loading branch information
allanmcarvalho committed Feb 25, 2017
1 parent fde0da8 commit d05d907
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Validation/DefaultValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,18 @@ protected static function checkTmpFile($check)
}
return true;
}

/**
* Verify if file input is a file array
* @param array $check
* @throws Exception
*/
protected static function checkInputType($check)
{
if (!is_array($check))
{
throw new Exception(__d('upload', "Misconfigured form"));
}
}

}
13 changes: 13 additions & 0 deletions src/Validation/ImageValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,18 @@ protected static function checkTmpFile($check)
}
return true;
}

/**
* Verify if file input is a file array
* @param array $check
* @throws Exception
*/
protected static function checkInputType($check)
{
if (!is_array($check))
{
throw new Exception(__d('upload', "Misconfigured form"));
}
}

}
9 changes: 9 additions & 0 deletions src/Validation/Traits/ImageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ protected static function greatestCommonDivisor($dividend_a, $dividend_b)
*/
public static function isAboveMinWidth($check, $width)
{
self::checkInputType();
if (!self::checkTmpFile($check))
{
return false;
Expand All @@ -75,6 +76,7 @@ public static function isAboveMinWidth($check, $width)
*/
public static function isBelowMaxWidth($check, $width)
{
self::checkInputType();
if (!self::checkTmpFile($check))
{
return false;
Expand All @@ -93,6 +95,7 @@ public static function isBelowMaxWidth($check, $width)
*/
public static function isAboveMinHeight($check, $height)
{
self::checkInputType();
if (!self::checkTmpFile($check))
{
return false;
Expand All @@ -111,6 +114,7 @@ public static function isAboveMinHeight($check, $height)
*/
public static function isBelowMaxHeight($check, $height)
{
self::checkInputType();
if (!self::checkTmpFile($check))
{
return false;
Expand All @@ -129,6 +133,7 @@ public static function isBelowMaxHeight($check, $height)
*/
public static function isThisWidth($check, $width)
{
self::checkInputType();
if (!self::checkTmpFile($check))
{
return false;
Expand All @@ -147,6 +152,7 @@ public static function isThisWidth($check, $width)
*/
public static function isThisHeight($check, $height)
{
self::checkInputType();
if (!self::checkTmpFile($check))
{
return false;
Expand All @@ -165,6 +171,7 @@ public static function isThisHeight($check, $height)
*/
public static function isThisWidthAndHeight($check, $width, $height)
{
self::checkInputType();
if (!self::checkTmpFile($check))
{
return false;
Expand All @@ -189,6 +196,7 @@ public static function isThisWidthAndHeight($check, $width, $height)
*/
public static function isThisAspectRatio($check, $width, $height)
{
self::checkInputType();
if (!self::checkTmpFile($check))
{
return false;
Expand Down Expand Up @@ -220,6 +228,7 @@ public static function isThisAspectRatio($check, $width, $height)
*/
public static function isThisExtension($check, $extensions = [])
{
self::checkInputType();
if (!self::checkTmpFile($check))
{
return false;
Expand Down
8 changes: 8 additions & 0 deletions src/Validation/Traits/UploadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ trait UploadTrait
*/
public static function isUnderPhpSizeLimit($check)
{
self::checkInputType();
return Hash::get($check, 'error') !== UPLOAD_ERR_INI_SIZE;
}

Expand All @@ -39,6 +40,7 @@ public static function isUnderPhpSizeLimit($check)
*/
public static function isUnderFormSizeLimit($check)
{
self::checkInputType();
return Hash::get($check, 'error') !== UPLOAD_ERR_FORM_SIZE;
}

Expand All @@ -50,6 +52,7 @@ public static function isUnderFormSizeLimit($check)
*/
public static function isCompletedUpload($check)
{
self::checkInputType();
return Hash::get($check, 'error') !== UPLOAD_ERR_PARTIAL;
}

Expand All @@ -61,6 +64,7 @@ public static function isCompletedUpload($check)
*/
public static function isFileUpload($check)
{
self::checkInputType();
return Hash::get($check, 'error') !== UPLOAD_ERR_NO_FILE;
}

Expand All @@ -72,6 +76,7 @@ public static function isFileUpload($check)
*/
public static function isSuccessfulWrite($check)
{
self::checkInputType();
return Hash::get($check, 'error') !== UPLOAD_ERR_CANT_WRITE;
}

Expand All @@ -84,6 +89,7 @@ public static function isSuccessfulWrite($check)
*/
public static function isAboveMinSize($check, $size)
{
self::checkInputType();
if (!self::checkTmpFile($check))
{
return false;
Expand All @@ -100,6 +106,7 @@ public static function isAboveMinSize($check, $size)
*/
public static function isBelowMaxSize($check, $size)
{
self::checkInputType();
if (!self::checkTmpFile($check))
{
return false;
Expand All @@ -115,6 +122,7 @@ public static function isBelowMaxSize($check, $size)
*/
public static function isThisMimeType($check, $mimeTypes = [])
{
self::checkInputType();
if (!self::checkTmpFile($check))
{
return false;
Expand Down
17 changes: 17 additions & 0 deletions src/Validation/UploadValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class UploadValidation
*/
protected static function checkTmpFile($check)
{
if (!is_array($check))
{
throw new Exception(__d('upload', "Misconfigured form"));
}
if (isset($check['tmp_name']))
{
if (!is_file($check['tmp_name']))
Expand All @@ -40,4 +44,17 @@ protected static function checkTmpFile($check)
return true;
}

/**
* Verify if file input is a file array
* @param array $check
* @throws Exception
*/
protected static function checkInputType($check)
{
if (!is_array($check))
{
throw new Exception(__d('upload', "Misconfigured form"));
}
}

}

0 comments on commit d05d907

Please sign in to comment.