Example #1
0
 /**
  * Returns the value of a specific binding parameter.
  *
  * @param string $parameterName  The name of the binding parameter.
  * @param bool   $includeDefault Whether to return the default value set
  *                               in the binding type if no value is set.
  *
  * @return mixed The parameter value.
  *
  * @throws NoSuchParameterException If the parameter does not exist.
  */
 public function getParameterValue($parameterName, $includeDefault = true)
 {
     if (isset($this->parameterValues[$parameterName])) {
         return $this->parameterValues[$parameterName];
     }
     if ($this->typeDescriptor) {
         if ($includeDefault) {
             return $this->typeDescriptor->getParameterValue($parameterName);
         }
         return null;
     }
     throw NoSuchParameterException::forParameterName($parameterName, $this->typeName);
 }
 private function assertBindingValid(BindingDescriptor $bindingDescriptor)
 {
     if ($bindingDescriptor->isTypeNotFound() || $bindingDescriptor->isTypeNotEnabled()) {
         return;
     }
     foreach ($bindingDescriptor->getViolations() 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());
         }
     }
 }
Example #3
0
 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());
         }
     }
 }