/**
  * @override
  */
 public static function build($context)
 {
     $childConstraints = [];
     $name = static::getName();
     $doc = $context->{$name};
     if (!is_array($doc)) {
         throw new ConstraintParseException('This keyword\'s value MUST be an array');
     }
     if (sizeof($doc) < 1) {
         throw new ConstraintParseException('This keyword\'s value MUST be an array.  This array MUST have at least one element.');
     }
     foreach ($doc as $of) {
         $childConstraints[] = EmptyConstraint::build($of);
     }
     return new static($childConstraints);
 }
 /**
  * @override
  */
 public static function build($context)
 {
     $doc = $context->dependencies;
     $dependencies = [];
     if (!is_object($doc)) {
         throw new ConstraintParseException('The value of "dependencies" MUST be an object.');
     }
     foreach ($doc as $key => $value) {
         if (is_object($value)) {
             $dependencies[$key] = EmptyConstraint::build($value);
         } elseif (is_array($value)) {
             $dependencies[$key] = $value;
         } else {
             throw new ConstraintParseException('The "dependencies" object must contain only object or array values.');
         }
     }
     return new static($dependencies);
 }
 /**
  * @dataProvider invalidConstraintDataProvider
  * @expectedException JsonSchema\Constraint\Exception\ConstraintParseException
  */
 public function testInvalidConstraint($schemaDoc)
 {
     $schemaDoc = json_decode($schemaDoc);
     $constraint = EmptyConstraint::build($schemaDoc);
 }
 /**
  *
  */
 public static function buildAdditionalPropertyConstraints($additionalProperties)
 {
     $constraint = true;
     if (is_bool($additionalProperties)) {
         $constraint = $additionalProperties;
     } elseif (is_object($additionalProperties)) {
         $constraint = EmptyConstraint::build($additionalProperties);
     } else {
         throw new ConstraintParseException('The value MUST be either a boolean or object.');
     }
     return $constraint;
 }
 /**
  * @override
  */
 public static function build($context)
 {
     $constraints = null;
     $doc = $context->items;
     if (!(is_array($doc) || is_object($doc))) {
         throw new ConstraintParseException("The value of 'items' MUST be either an object or an array.");
     }
     if (isset($context->additionalItems) && !(is_bool($context->additionalItems) || is_object($context->additionalItems))) {
         throw new ConstraintParseException("The value of 'additionalItems' MUST be either a boolean or an object.");
     }
     if (is_array($doc)) {
         $constraints = [];
         foreach ($doc as $value) {
             $constraints[] = EmptyConstraint::build($value);
         }
     } else {
         $constraints = EmptyConstraint::build($context->items);
     }
     $additionalItems = isset($context->additionalItems) ? $context->additionalItems : true;
     if (is_object($additionalItems)) {
         $additionalItems = EmptyConstraint::build($additionalItems);
     }
     return new static($constraints, $additionalItems);
 }
Exemplo n.º 6
0
 /**
  * Construct a validator from a JSON document data structure.
  * Note the $doc structure underlying the JsonDocs is mutated to aid in stuff.
  */
 public function __construct(\StdClass $doc)
 {
     $this->doc = $doc;
     $this->rootSymbol = EmptyConstraint::build($doc);
 }
 private static function parseConditional($doc)
 {
     if (!is_object($doc)) {
         throw new ConstraintParseException('The items in a "switch" array MUST be objects.');
     }
     if (isset($doc->continue) && !is_bool($doc->continue)) {
         throw new ConstraintParseException('The value of "continue" MUST be a boolean.');
     }
     if (!isset($doc->then)) {
         throw new ConstraintParseException('"then" must be specified.');
     }
     if (!(is_bool($doc->then) || is_object($doc->then))) {
         throw new ConstraintParseException('"then" must be an object or boolean.');
     }
     if (is_object($doc->then)) {
         $doc->then = EmptyConstraint::build($doc->then);
     }
     if (isset($doc->if)) {
         if (!is_object($doc->if)) {
             throw new ConstraintParseException('The value of "if" MUST be an object.');
         }
         $doc->if = EmptyConstraint::build($doc->if);
     }
     return $doc;
 }