/** * @param ArrayValue\ItemsConstraint $constraint * * @return Result\ValidationResult */ public function visitItemsConstraint(ArrayValue\ItemsConstraint $constraint) { $value = $this->currentValue(); if (!$value instanceof Value\ArrayValue) { return $this->createResult(); } $result = $this->createResult(); $matchedIndices = array(); // items foreach ($constraint->schemas() as $index => $schema) { if ($value->has($index)) { $matchedIndices[$index] = true; $result = $result->merge($this->validateArrayIndex($index, $schema)); } elseif (null !== $schema->defaultValue()) { $result = $result->merge($this->createResult(array(), array($this->createDefaultValueMatch($schema, $index)))); } } // additional items foreach ($value->keys() as $index) { if (!array_key_exists($index, $matchedIndices)) { $result = $result->merge($this->validateArrayIndex($index, $constraint->additionalSchema())); } } return $result; }
/** * @param ArrayValue\ItemsConstraint $constraint * * @return ArrayValue\ItemsConstraint */ public function visitItemsConstraint(ArrayValue\ItemsConstraint $constraint) { return new ArrayValue\ItemsConstraint($this->transformConstraintArray($constraint->schemas()), $constraint->additionalSchema()->accept($this)); }