Created
January 6, 2014 11:42
-
-
Save J7mbo/8281652 to your computer and use it in GitHub Desktop.
PHP JSON Validator Class
This file contains hidden or 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
| 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