forked from LiveCarta/PayPal-PHP-SDK
Enabled EC Parameters support
- Updated Api to enabled EC Parameters - Updated Tests - Updated Logging Manager - Added a feature to do validation on accessors.
This commit is contained in:
37
lib/PayPal/Validation/ArgumentValidator.php
Normal file
37
lib/PayPal/Validation/ArgumentValidator.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Validation;
|
||||
|
||||
/**
|
||||
* Class ArgumentValidator
|
||||
*
|
||||
* @package PayPal\Validation
|
||||
*/
|
||||
class ArgumentValidator
|
||||
{
|
||||
|
||||
/**
|
||||
* Helper method for validating an argument that will be used by this API in any requests.
|
||||
*
|
||||
* @param $argument mixed The object to be validated
|
||||
* @param $argumentName string|null The name of the argument.
|
||||
* This will be placed in the exception message for easy reference
|
||||
*/
|
||||
public static function validate($argument, $argumentName = null)
|
||||
{
|
||||
if (
|
||||
$argument != null &&
|
||||
(
|
||||
(gettype($argument) == 'string' && $argument == '')
|
||||
||
|
||||
is_array($argument) && empty($argument)
|
||||
)
|
||||
) {
|
||||
//Throw an Exception for string or array
|
||||
throw new \InvalidArgumentException("$argumentName cannot be null or empty");
|
||||
} elseif ($argument == null) {
|
||||
//Generic Exception
|
||||
throw new \InvalidArgumentException("$argumentName cannot be null");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user