src/Nugget.php
3. namespace Activerules\Nugget;
5. use Activerules\Nugget\Exceptions\NuggetException;
14. * Create a new Skeleton Instance
16. public function __construct()
21. * Determine if an object is valid
23. * @param string $object, JSON serialized object
24. * @param type $schema
27. public function meetsSchema(string $object, $schema)
29. $data = json_decode($object);
New instance (Activerules\JsonGuard\Validator)
31. $validator = new \Activerules\JsonGuard\Validator($data, $schema);
33. return $validator->fails() ? false : true ;
37. * Remove all properties not defined in the schema
39. * @param string $object
40. * @param type $schema
43. public function limitToSchema(string $object, $schema, $jsonOut=true)
45. $data = json_decode($object);
47. // We loop through the top level schema objects and only use the data elements defined therein.
48. // We don't loop though data becasue it could be much larger than the schema.
49. // Start with an empty array.
52. foreach($schema->properties as $prop => $val) {
53. if(isset($data->$prop)) {
54. $cleanObject[$prop] = $data->$prop;
58. return $jsonOut ? json_encode($cleanObject) : $cleanObject;