mirror of
https://github.com/justinrainbow/json-schema.git
synced 2025-05-02 04:18:09 +02:00
add instance cache, remove unnecessary execution paths (#288)
fix wrong merge
This commit is contained in:
parent
1296583112
commit
0f87b314cd
@ -23,7 +23,7 @@ class Factory
|
||||
* @var SchemaStorage
|
||||
*/
|
||||
protected $schemaStorage;
|
||||
|
||||
|
||||
/**
|
||||
* @var UriRetriever $uriRetriever
|
||||
*/
|
||||
@ -56,6 +56,11 @@ class Factory
|
||||
'validator' => 'JsonSchema\Validator',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array<ConstraintInterface>
|
||||
*/
|
||||
private $instanceCache = array();
|
||||
|
||||
/**
|
||||
* @param SchemaStorage $schemaStorage
|
||||
* @param UriRetrieverInterface $uriRetriever
|
||||
@ -78,7 +83,7 @@ class Factory
|
||||
{
|
||||
return $this->uriRetriever;
|
||||
}
|
||||
|
||||
|
||||
public function getSchemaStorage()
|
||||
{
|
||||
return $this->schemaStorage;
|
||||
@ -124,12 +129,15 @@ class Factory
|
||||
public function createInstanceFor($constraintName)
|
||||
{
|
||||
if (array_key_exists($constraintName, $this->constraintMap)) {
|
||||
return new $this->constraintMap[$constraintName](
|
||||
$this->checkMode,
|
||||
$this->schemaStorage,
|
||||
$this->uriRetriever,
|
||||
$this
|
||||
);
|
||||
if (!isset($this->instanceCache[$constraintName])) {
|
||||
$this->instanceCache[$constraintName] = new $this->constraintMap[$constraintName](
|
||||
$this->checkMode,
|
||||
$this->schemaStorage,
|
||||
$this->uriRetriever,
|
||||
$this
|
||||
);
|
||||
}
|
||||
return clone $this->instanceCache[$constraintName];
|
||||
}
|
||||
throw new InvalidArgumentException('Unknown constraint ' . $constraintName);
|
||||
}
|
||||
|
@ -105,11 +105,6 @@ class ObjectConstraint extends Constraint
|
||||
$this->addError($path, "The presence of the property " . $i . " requires that " . $require . " also be present", 'requires');
|
||||
}
|
||||
|
||||
if (!$definition) {
|
||||
// normal property verification
|
||||
$this->checkUndefined($value, new \stdClass(), $path, $i);
|
||||
}
|
||||
|
||||
$property = $this->getProperty($element, $i, new UndefinedConstraint());
|
||||
if (is_object($property)) {
|
||||
$this->validateMinMaxConstraint(!($property instanceof UndefinedConstraint) ? $property : $element, $definition, $path);
|
||||
@ -129,7 +124,11 @@ class ObjectConstraint extends Constraint
|
||||
foreach ($objectDefinition as $i => $value) {
|
||||
$property = $this->getProperty($element, $i, $this->getFactory()->createInstanceFor('undefined'));
|
||||
$definition = $this->getProperty($objectDefinition, $i);
|
||||
$this->checkUndefined($property, $definition, $path, $i);
|
||||
|
||||
if (is_object($definition)) {
|
||||
// Undefined constraint will check for is_object() and quit if is not - so why pass it?
|
||||
$this->checkUndefined($property, $definition, $path, $i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user