/** * Loads the binding descriptor. * * @param Package $containingPackage The package that contains * the descriptor. * @param BindingTypeDescriptor $typeDescriptor The type descriptor. * * @throws AlreadyLoadedException If the descriptor is already loaded. */ public function load(Package $containingPackage, BindingTypeDescriptor $typeDescriptor = null) { if (null !== $this->state) { throw new AlreadyLoadedException('The binding descriptor is already loaded.'); } if ($typeDescriptor && $this->typeName !== $typeDescriptor->getName()) { throw new InvalidArgumentException(sprintf('The passed type "%s" does not match the stored type name "%s".', $typeDescriptor->getName(), $this->typeName)); } $this->violations = array(); if ($typeDescriptor && $typeDescriptor->isLoaded() && $typeDescriptor->isEnabled()) { $validator = new SimpleParameterValidator(); $bindingType = $typeDescriptor->toBindingType(); $this->violations = $validator->validate($this->parameterValues, $bindingType); } $this->containingPackage = $containingPackage; $this->typeDescriptor = $typeDescriptor; $this->refreshState(); }
private function assertParametersValid(array $parameterValues, BindingType $type) { $validator = new SimpleParameterValidator(); $violations = $validator->validate($parameterValues, $type); foreach ($violations as $violation) { switch ($violation->getCode()) { case ConstraintViolation::NO_SUCH_PARAMETER: throw NoSuchParameterException::forParameterName($violation->getParameterName(), $violation->getTypeName()); case ConstraintViolation::MISSING_PARAMETER: throw MissingParameterException::forParameterName($violation->getParameterName(), $violation->getTypeName()); } } }