Esempio n. 1
0
 public function __construct($value)
 {
     if (!$value instanceof Schema) {
         throw new \InvalidArgumentException("Not constraints require the value to be a Schema");
     }
     parent::__construct($value);
 }
Esempio n. 2
0
 public function __construct($value)
 {
     if (!is_array($value)) {
         throw new \InvalidArgumentException("The " . __CLASS__ . " constraint requires an array of values");
     }
     foreach ($value as $i => $schema) {
         if (!$schema instanceof Schema) {
             throw new \InvalidArgumentException("The element for key: {$i} was not a schema object");
         }
     }
     if (empty($value)) {
         throw new \InvalidArgumentException("The value array did not contain any schema objects");
     }
     parent::__construct($value);
 }
Esempio n. 3
0
 public function validate($data)
 {
     parent::validate($data);
     $dataVars = get_object_vars($data);
     foreach ($this->value as $name => $dependency) {
         if (isset($dataVars[$name])) {
             if ($dependency instanceof Schema) {
                 $dependency->validate($data);
             } else {
                 foreach ($dependency as $dependantProperty) {
                     if (!isset($datVars[$dependantProperty])) {
                         $this->throwException("RequirementException", "The data is dependant on a non existent property", $dependantProperty);
                     }
                 }
             }
         }
     }
 }
Esempio n. 4
0
 public function validate($data)
 {
     parent::validate($data);
     if ($this->additionalItems === true || empty($this->value)) {
         return;
     }
     if (!is_array($data)) {
         $this->throwException("ValueException", "When checking Items, the data is required to be in array format");
     }
     // value is a schemata
     if ($this->value instanceof Schema) {
         // the draft 4 documentation is confused on this point
         // section 5.3.1.2 says this is an automatic success
         // section 8.2.3.1 says the data needs to validate against the value
         foreach ($data as $item) {
             $this->value->validate($item);
         }
         return;
     }
     // value is an array of schema
     foreach ($data as $key => $item) {
         if (!is_numeric($key)) {
             throw new \InvalidArgumentException("JSONSchema arrays must be numerically indexed");
         }
         if (isset($this->value[$key])) {
             /** @var Schema $value */
             $value = $this->value[$key];
             $value->validate($item);
         } elseif ($this->additionalItems instanceof Schema) {
             // the draft 4 documentation is confused on this point
             // section 5.3.1.2 says this is an automatic success
             // section 8.2.3.2 says the data needs to validate against the value of additionalItems
             $this->additionalItems->validate($item);
         } else {
             $this->throwException("ValueException", "The array contained more elements than are allowed");
         }
     }
 }
 public function validate($data)
 {
     parent::validate($data);
     if ($this->value === true) {
         return;
     }
     // only process properties if they have not been checked already;
     $dataVars = get_object_vars($data);
     foreach ($dataVars as $name => $value) {
         if (!isset($this->checkedProperties[$name])) {
             if ($this->value instanceof Schema) {
                 // draft 4 documentation is confused at this point
                 // 5.4.4.2 says that this is an automatic success
                 // 8.3.3.4 says that the data needs to validate against the value schemata
                 $this->value->validate($value);
             } else {
                 // value is boolean false
                 $this->throwException("RequirementException", "A property was present in the data that was not allowed by the schema", $name);
             }
         }
     }
     //*/
 }
Esempio n. 6
0
 public function validate($data)
 {
     parent::validate($data);
     $this->checkProperties($this->value, $data);
 }