Exemplo n.º 1
0
 /**
  * @throws CyclicDependencyInDiConfig
  *
  * @param DiConfig    $diConfig
  * @param ServiceId   $originallyRequestedServiceId
  * @param ServiceId   $serviceIdToTest
  * @param ServiceId[] $parentDependencies
  */
 private function cyclicDependencyTest(DiConfig $diConfig, ServiceId $originallyRequestedServiceId, ServiceId $serviceIdToTest, $parentDependencies)
 {
     if (in_array($serviceIdToTest, $parentDependencies)) {
         throw CyclicDependencyInDiConfig::constructWithServiceId($originallyRequestedServiceId);
     }
     foreach ($diConfig->getArguments($serviceIdToTest) as $childDependencyId) {
         $this->cyclicDependencyTest($diConfig, $originallyRequestedServiceId, $childDependencyId, $this->mergeArrays($parentDependencies, [$serviceIdToTest]));
     }
 }
Exemplo n.º 2
0
 /**
  * @param ServiceId $serviceId
  * @return object
  */
 private function buildObject(ServiceId $serviceId)
 {
     $classname = $this->diConfig->getClassname($serviceId);
     if ($this->diConfig->serviceHasNoArguments($serviceId)) {
         return new $classname();
     }
     $arguments = [];
     foreach ($this->diConfig->getArguments($serviceId) as $argumentServiceId) {
         $arguments[] = $this->get($argumentServiceId);
     }
     return $this->objectBuilder->buildObject($classname, $arguments);
 }