예제 #1
0
 /**
  * @param ObjectValue\PropertiesConstraint $constraint
  *
  * @return Result\ValidationResult
  */
 public function visitPropertiesConstraint(ObjectValue\PropertiesConstraint $constraint)
 {
     $value = $this->currentValue();
     if (!$value instanceof Value\ObjectValue) {
         return $this->createResult();
     }
     $result = $this->createResult();
     $matchedProperties = array();
     // properties
     foreach ($constraint->schemas() as $property => $schema) {
         if ($value->has($property)) {
             $matchedProperties[$property] = true;
             $result = $result->merge($this->validateObjectProperty($property, $schema));
         } elseif (null !== $schema->defaultValue()) {
             $result = $result->merge($this->createResult(array(), array($this->createDefaultValueMatch($schema, $property))));
         }
     }
     // pattern properties
     foreach ($constraint->patternSchemas() as $pattern => $schema) {
         $pattern = $this->wrapPattern($pattern);
         foreach ($value->keys() as $property) {
             if (preg_match($pattern, $property)) {
                 $matchedProperties[$property] = true;
                 $result = $result->merge($this->validateObjectProperty($property, $schema));
             }
         }
     }
     // additional properties
     foreach ($value->keys() as $property) {
         if (!array_key_exists($property, $matchedProperties)) {
             $result = $result->merge($this->validateObjectProperty($property, $constraint->additionalSchema()));
         }
     }
     return $result;
 }
 /**
  * @param ObjectValue\PropertiesConstraint $constraint
  *
  * @return ObjectValue\PropertiesConstraint
  */
 public function visitPropertiesConstraint(ObjectValue\PropertiesConstraint $constraint)
 {
     return new ObjectValue\PropertiesConstraint($this->transformConstraintArray($constraint->schemas()), $this->transformConstraintArray($constraint->patternSchemas()), $constraint->additionalSchema()->accept($this));
 }