Skip to content

Instantly share code, notes, and snippets.

@J7mbo
Created January 6, 2014 11:42
Show Gist options
  • Select an option

  • Save J7mbo/8281652 to your computer and use it in GitHub Desktop.

Select an option

Save J7mbo/8281652 to your computer and use it in GitHub Desktop.
PHP JSON Validator Class
namespace Seedstream\Websocket\Handler\Request\Validator;
/**
* {@inheritdoc}
*/
class JSONValidator implements ValidatorInterface
{
/**
* {@inheritdoc}
*/
public function validate($data)
{
if (is_string($data) && $data !== "")
{
$data = json_decode($data);
if (!is_null($data) && json_last_error() === JSON_ERROR_NONE)
{
if (is_object($data))
{
$data = get_object_vars($data);
}
if (is_array($data))
{
return $data;
}
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment