Пример #1
0
 /**
  * Build service. We assume that the service exists and can be build
  *
  * @param string $serviceName Service Name
  *
  * @return mixed Service instance
  */
 protected function buildExistentService($serviceName)
 {
     $serviceDefinition = $this->services->get($serviceName);
     $serviceReflectionClass = new ReflectionClass($serviceDefinition->getClass());
     $serviceArguments = array();
     /**
      * Each argument is built recursively. If the argument is defined
      * as a service we will return the value of the get() call.
      *
      * Otherwise, if is defined as a parameter we will return the
      * parameter value
      *
      * Otherwise, we will treat the value as a plain value, not precessed.
      */
     $serviceDefinition->getArgumentChain()->each(function (Argument $argument) use(&$serviceArguments) {
         $argumentValue = $argument->getValue();
         if ($argument instanceof ServiceArgument) {
             $serviceArguments[] = $this->get($argumentValue);
         } elseif ($argument instanceof ParameterArgument) {
             $serviceArguments[] = $this->getParameter($argumentValue);
         } else {
             $serviceArguments[] = $argumentValue;
         }
     });
     return $serviceReflectionClass->newInstanceArgs($serviceArguments);
 }