-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted a validation utility class
- Loading branch information
1 parent
c5e2c33
commit 5e936c7
Showing
7 changed files
with
66 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/** | ||
* Created by PhpStorm. | ||
* User: milos.pejanovic | ||
* Date: 7/26/2016 | ||
* Time: 9:23 AM | ||
*/ | ||
namespace Common\Util; | ||
|
||
class Validation { | ||
|
||
/** | ||
* Checks for null, '', and empty arrays | ||
* Casts objects to arrays before checking | ||
* @param mixed $value | ||
* @return bool | ||
*/ | ||
public static function isEmpty($value) { | ||
$isEmpty = false; | ||
if(is_object($value)) { | ||
$value = (array) $value; | ||
} | ||
if($value === array() || is_null($value) || $value === '') { | ||
$isEmpty= true; | ||
} | ||
|
||
return $isEmpty; | ||
} | ||
|
||
/** | ||
* Checks if a type is of a custom object or simple | ||
* @param string $type | ||
* @return bool | ||
*/ | ||
public static function isCustomType(string $type) { | ||
$result = true; | ||
$simpleTypes = ['boolean', 'integer', 'double', 'string', 'array', 'object', | ||
'boolean[]', 'integer[]', 'double[]', 'string[]', '[]', 'object[]']; | ||
foreach($simpleTypes as $simpleType) { | ||
if($type == $simpleType) { | ||
$result = false; | ||
break; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters