Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function addBindingType(BindingType $type)
 {
     if (isset($this->types[$type->getName()])) {
         throw DuplicateTypeException::forTypeName($type->getName());
     }
     $this->types[$type->getName()] = $type;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function addBindingType(BindingType $type)
 {
     if (null === $this->json) {
         $this->load();
     }
     if (isset($this->json['keysByTypeName'][$type->getName()])) {
         throw DuplicateTypeException::forTypeName($type->getName());
     }
     $key = $this->json['nextKey']++;
     $this->json['keysByTypeName'][$type->getName()] = $key;
     $this->typesByKey[$key] = $type;
     // Use integer keys to reduce storage space
     // (compared to fully-qualified class names)
     $this->json['typesByKey'][$key] = serialize($type);
     $this->flush();
 }
 /**
  * Returns the description for a parameter.
  *
  * @param string $parameterName The parameter name.
  *
  * @return string The description of the parameter.
  *
  * @throws NoSuchParameterException If the parameter does not exist.
  * @throws OutOfBoundsException     If the parameter has no description.
  */
 public function getParameterDescription($parameterName)
 {
     if (!$this->type->hasParameter($parameterName)) {
         throw new NoSuchParameterException(sprintf('The parameter "%s" does not exist.', $parameterName));
     }
     if (!isset($this->parameterDescriptions[$parameterName])) {
         throw new OutOfBoundsException(sprintf('No description exists for parameter "%s".', $parameterName));
     }
     return $this->parameterDescriptions[$parameterName];
 }
 public function testUnrestrictedBindingClasses()
 {
     $type = new BindingType(Foo::clazz);
     $this->assertTrue($type->acceptsBinding(self::RESOURCE_BINDING));
     $this->assertTrue($type->acceptsBinding(self::CLASS_BINDING));
     $this->assertSame(array(), $type->getAcceptedBindings());
 }
 /**
  * {@inheritdoc}
  */
 public function addBindingType(BindingType $type)
 {
     if (isset($this->keysByTypeName[$type->getName()])) {
         throw DuplicateTypeException::forTypeName($type->getName());
     }
     $key = $this->nextKey++;
     $this->keysByTypeName[$type->getName()] = $key;
     // Use integer keys to reduce storage space
     // (compared to fully-qualified class names)
     $this->typesByKey[$key] = $type;
     $this->store->set('::keysByTypeName', $this->keysByTypeName);
     $this->store->set('::nextKey', $this->nextKey);
     $this->store->set('t:' . $key, $type);
 }
Esempio n. 6
0
 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());
             }
         }
     }
 }