Added php-opencloud/openstack as SubModule
This commit is contained in:
parent
eac860ce50
commit
81d5c2a646
15 changed files with 282 additions and 178 deletions
|
@ -36,7 +36,7 @@
|
|||
}
|
||||
}],
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
"php": ">=5.3.29"
|
||||
},
|
||||
"require-dev": {
|
||||
"json-schema/JSON-Schema-Test-Suite": "1.1.0",
|
||||
|
@ -52,7 +52,7 @@
|
|||
"bin": ["bin/validate-json"],
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.4.x-dev"
|
||||
"dev-master": "1.6.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,27 @@ use JsonSchema\Validator;
|
|||
class Factory
|
||||
{
|
||||
/**
|
||||
* @var UriRetriever
|
||||
* @var UriRetriever $uriRetriever
|
||||
*/
|
||||
protected $uriRetriever;
|
||||
|
||||
/**
|
||||
* @var array $constraintMap
|
||||
*/
|
||||
protected $constraintMap = array(
|
||||
'array' => 'JsonSchema\Constraints\CollectionConstraint',
|
||||
'collection' => 'JsonSchema\Constraints\CollectionConstraint',
|
||||
'object' => 'JsonSchema\Constraints\ObjectConstraint',
|
||||
'type' => 'JsonSchema\Constraints\TypeConstraint',
|
||||
'undefined' => 'JsonSchema\Constraints\UndefinedConstraint',
|
||||
'string' => 'JsonSchema\Constraints\StringConstraint',
|
||||
'number' => 'JsonSchema\Constraints\NumberConstraint',
|
||||
'enum' => 'JsonSchema\Constraints\EnumConstraint',
|
||||
'format' => 'JsonSchema\Constraints\FormatConstraint',
|
||||
'schema' => 'JsonSchema\Constraints\SchemaConstraint',
|
||||
'validator' => 'JsonSchema\Validator',
|
||||
);
|
||||
|
||||
/**
|
||||
* @param UriRetriever $uriRetriever
|
||||
*/
|
||||
|
@ -43,6 +60,25 @@ class Factory
|
|||
return $this->uriRetriever;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @return Factory
|
||||
*/
|
||||
public function setConstraintClass($name, $class)
|
||||
{
|
||||
// Ensure class exists
|
||||
if (!class_exists($class)) {
|
||||
throw new InvalidArgumentException('Unknown constraint ' . $name);
|
||||
}
|
||||
// Ensure class is appropriate
|
||||
if (!in_array('JsonSchema\Constraints\ConstraintInterface', class_implements($class))) {
|
||||
throw new InvalidArgumentException('Invalid class ' . $name);
|
||||
}
|
||||
$this->constraintMap[$name] = $class;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a constraint instance for the given constraint name.
|
||||
*
|
||||
|
@ -52,30 +88,9 @@ class Factory
|
|||
*/
|
||||
public function createInstanceFor($constraintName)
|
||||
{
|
||||
switch ($constraintName) {
|
||||
case 'array':
|
||||
case 'collection':
|
||||
return new CollectionConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
|
||||
case 'object':
|
||||
return new ObjectConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
|
||||
case 'type':
|
||||
return new TypeConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
|
||||
case 'undefined':
|
||||
return new UndefinedConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
|
||||
case 'string':
|
||||
return new StringConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
|
||||
case 'number':
|
||||
return new NumberConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
|
||||
case 'enum':
|
||||
return new EnumConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
|
||||
case 'format':
|
||||
return new FormatConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
|
||||
case 'schema':
|
||||
return new SchemaConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
|
||||
case 'validator':
|
||||
return new Validator(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
|
||||
if (array_key_exists($constraintName, $this->constraintMap)) {
|
||||
return new $this->constraintMap[$constraintName](Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException('Unknown constraint ' . $constraintName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ class NumberConstraint extends Constraint
|
|||
// Verify minimum
|
||||
if (isset($schema->exclusiveMinimum)) {
|
||||
if (isset($schema->minimum)) {
|
||||
if ($schema->exclusiveMinimum && $element === $schema->minimum) {
|
||||
$this->addError($path, "Must have a minimum value greater than boundary value of " . $schema->minimum, 'exclusiveMinimum', array('minimum' => $schema->minimum,));
|
||||
if ($schema->exclusiveMinimum && $element <= $schema->minimum) {
|
||||
$this->addError($path, "Must have a minimum value of " . $schema->minimum, 'exclusiveMinimum', array('minimum' => $schema->minimum,));
|
||||
} else if ($element < $schema->minimum) {
|
||||
$this->addError($path, "Must have a minimum value of " . $schema->minimum, 'minimum', array('minimum' => $schema->minimum,));
|
||||
}
|
||||
|
@ -40,8 +40,8 @@ class NumberConstraint extends Constraint
|
|||
// Verify maximum
|
||||
if (isset($schema->exclusiveMaximum)) {
|
||||
if (isset($schema->maximum)) {
|
||||
if ($schema->exclusiveMaximum && $element === $schema->maximum) {
|
||||
$this->addError($path, "Must have a maximum value less than boundary value of " . $schema->maximum, 'exclusiveMaximum', array('maximum' => $schema->maximum,));
|
||||
if ($schema->exclusiveMaximum && $element >= $schema->maximum) {
|
||||
$this->addError($path, "Must have a maximum value of " . $schema->maximum, 'exclusiveMaximum', array('maximum' => $schema->maximum,));
|
||||
} else if ($element > $schema->maximum) {
|
||||
$this->addError($path, "Must have a maximum value of " . $schema->maximum, 'maximum', array('maximum' => $schema->maximum,));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue