Пример #1
0
 /**
  * {@inheritDoc}
  */
 public function check($value = null, $schema = null, $path = null, $i = null)
 {
     $type = isset($schema->type) ? $schema->type : null;
     $isValid = true;
     if (is_array($type)) {
         // @TODO refactor
         $validatedOneType = false;
         $errors = array();
         foreach ($type as $tp) {
             $validator = new TypeConstraint($this->checkMode);
             $subSchema = new \stdClass();
             $subSchema->type = $tp;
             $validator->check($value, $subSchema, $path, null);
             $error = $validator->getErrors();
             if (!count($error)) {
                 $validatedOneType = true;
                 break;
             }
             $errors = $error;
         }
         if (!$validatedOneType) {
             return $this->addErrors($errors);
         }
     } elseif (is_object($type)) {
         $this->checkUndefined($value, $type, $path);
     } else {
         $isValid = $this->validateType($value, $type);
     }
     if ($isValid === false) {
         if (!isset(self::$wording[$type])) {
             throw new StandardUnexpectedValueException(sprintf("No wording for %s available, expected wordings are: [%s]", var_export($type, true), implode(', ', array_filter(self::$wording))));
         }
         $this->addError($path, gettype($value) . " value found, but " . self::$wording[$type] . " is required");
     }
 }
Пример #2
0
 /**
  * Validates the type of a property
  *
  * @param mixed $value
  * @param mixed $schema
  * @param mixed $path
  * @param mixed $i
  */
 protected function checkType($value, $schema = null, $path = null, $i = null)
 {
     $validator = new TypeConstraint($this->checkMode, $this->uriRetriever, $this->uriResolver, $this->schemaId);
     $validator->check($value, $schema, $path, $i);
     $this->addErrors($validator->getErrors());
 }
Пример #3
0
 /**
  * @dataProvider provideIndefiniteArticlesForTypes
  */
 public function testIndefiniteArticleForTypeInTypeCheckErrorMessage($type, $wording, $value = null, $label = 'NULL')
 {
     $constraint = new TypeConstraint();
     $constraint->check($value, (object) array('type' => $type));
     $this->assertTypeConstraintError("{$label} value found, but {$wording} {$type} is required", $constraint);
 }