Ejemplo n.º 1
0
 /** @covers Brickoo\Component\IoC\Definition\ArgumentDefinition::hasName */
 public function testHasName()
 {
     $annotationDefinition = new ArgumentDefinition("some value");
     $this->assertFalse($annotationDefinition->hasName());
     $annotationDefinition = new ArgumentDefinition("some value", "MyAnnotation");
     $this->assertTrue($annotationDefinition->hasName());
 }
 /**
  * Adds an argument to the dependency definition.
  * @param \Brickoo\Component\IoC\Definition\ArgumentDefinition $argument
  * @throws \Brickoo\Component\IoC\Definition\Container\Exception\DuplicateParameterDefinitionException
  * @return \Brickoo\Component\IoC\Definition\Container\ArgumentDefinitionContainer
  */
 public function addArgument(ArgumentDefinition $argument)
 {
     if (($hasName = $argument->hasName()) && $this->contains($argument->getName())) {
         throw new DuplicateParameterDefinitionException($argument->getName());
     }
     $argumentKey = $hasName ? $argument->getName() : uniqid("arg:");
     $this->add($argumentKey, $argument);
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Returns the argument definition resolved value.
  * @param \Brickoo\Component\IoC\Definition\ArgumentDefinition $argument
  * @return mixed the argument value
  */
 private function getArgumentValue(ArgumentDefinition $argument)
 {
     $argumentValue = $argument->getValue();
     if (is_callable($argumentValue)) {
         return call_user_func($argumentValue, $this->getDiContainer());
     }
     if (is_string($argumentValue) && strpos($argumentValue, $this->definitionPrefix) === 0) {
         return $this->getDiContainer()->retrieve(substr($argumentValue, strlen($this->definitionPrefix)));
     }
     return $argumentValue;
 }