/** * Creates a binding type descriptor. * * @param BindingType $type The described type. * @param string|null $description A human-readable description of * the type. * @param string[] $parameterDescriptions Human-readable descriptions * indexed by the type's parameter * names. * * @throws NoSuchParameterException If a description is passed for an unset * parameter. */ public function __construct(BindingType $type, $description = null, array $parameterDescriptions = array()) { Assert::nullOrStringNotEmpty($description, 'The description must be a non-empty string or null. Got: %s'); Assert::allStringNotEmpty($parameterDescriptions, 'The parameter description must be a non-empty string. Got: %s'); $this->type = $type; $this->description = $description; foreach ($parameterDescriptions as $parameterName => $parameterDescription) { if (!$type->hasParameter($parameterName)) { throw NoSuchParameterException::forParameterName($parameterName, $type->getName()); } $this->parameterDescriptions[$parameterName] = $parameterDescription; } }
private function assertParameterValuesValid(array $parameterValues, BindingType $type) { foreach ($parameterValues as $name => $value) { if (!$type->hasParameter($name)) { throw NoSuchParameterException::forParameterName($name, $type->getName()); } } foreach ($type->getParameters() as $parameter) { if (!isset($parameterValues[$parameter->getName()])) { if ($parameter->isRequired()) { throw MissingParameterException::forParameterName($parameter->getName(), $type->getName()); } } } }