Пример #1
0
 public function testThatForcedInstanceIsNotStored()
 {
     $this->factory->setParameters(TestClass::class, ['a' => 'armadillo', 'b' => 'banana']);
     $objectA = $this->factory->get(TestClass::class, [], true);
     $object = $this->factory->get(TestClass::class);
     $objectB = $this->factory->get(TestClass::class, [], true);
     $objectC = $this->factory->get(TestClass::class);
     $this->assertNotSame($object, $objectA);
     $this->assertNotSame($object, $objectB);
     $this->assertNotSame($objectA, $objectB);
     $this->assertSame($object, $objectC);
 }
Пример #2
0
 protected function resolveParameter($parameters, \ReflectionParameter $constructorArg)
 {
     $parameterName = $constructorArg->getName();
     $parameterPosition = $constructorArg->getPosition();
     if (isset($parameters[$parameterName])) {
         return $parameters[$parameterName];
     } else {
         if (isset($parameters[$parameterPosition])) {
             return $parameters[$parameterPosition];
         } else {
             if (isset($this->parameters[$parameterName])) {
                 return $this->parameters[$parameterName];
             } else {
                 if (isset($this->parameters[$parameterPosition])) {
                     return $this->parameters[$parameterPosition];
                 } else {
                     if ($constructorArg->getClass() !== null) {
                         try {
                             return $this->factory->get($constructorArg->getClass()->getName());
                         } catch (InstantiationException $e) {
                             if ($constructorArg->isDefaultValueAvailable()) {
                                 return $constructorArg->getDefaultValue();
                             } else {
                                 throw $e;
                             }
                         }
                     } else {
                         if ($constructorArg->isDefaultValueAvailable()) {
                             return $constructorArg->getDefaultValue();
                         } else {
                             throw new ParameterMissingException($parameterName);
                         }
                     }
                 }
             }
         }
     }
 }