mirror of
https://github.com/Karaka-Management/Resources.git
synced 2026-01-25 10:48:41 +00:00
36 lines
872 B
PHP
36 lines
872 B
PHP
<?php
|
|
|
|
namespace PayPal\Validation;
|
|
|
|
/**
|
|
* Class JsonValidator
|
|
*
|
|
* @package PayPal\Validation
|
|
*/
|
|
class JsonValidator
|
|
{
|
|
|
|
/**
|
|
* Helper method for validating if string provided is a valid json.
|
|
*
|
|
* @param string $string String representation of Json object
|
|
* @param bool $silent Flag to not throw \InvalidArgumentException
|
|
* @return bool
|
|
*/
|
|
public static function validate($string, $silent = false)
|
|
{
|
|
@json_decode($string);
|
|
if (json_last_error() != JSON_ERROR_NONE) {
|
|
if ($string === '' || $string === null) {
|
|
return true;
|
|
}
|
|
if ($silent == false) {
|
|
//Throw an Exception for string or array
|
|
throw new \InvalidArgumentException("Invalid JSON String");
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|