src/Container.php
protected function generateService($definition)
    {
        $reflection = new \ReflectionClass($definition->getClass());
        $arguments = $definition->getArguments();
        $properties = $definition->getProperties();
        $calls = $definition->getCalls();

        if (count($arguments) > 0) {
            foreach ($arguments as &$argument) {
                if (is_string($argument)) {
                    if ('@' === $argument[0]) {
                        $serviceId = substr($argument, 1);
                        $subDefinition = $this->getDefinition($serviceId);
                        $argument = $this->generateService($subDefinition);
                    } else if (strlen($argument) > 2 && '%' === $argument[0] && '%' === substr($argument, -1)) {
                        $parameterId = substr($argument, 1, -1);
                        $argument = $this->getParameter($parameterId);
                    }
                }
            }

            $service = $reflection->newInstanceArgs($arguments);
        } else {
            $service = $reflection->newInstance();
        }

        if (count($properties) > 0) {
            foreach ($properties as $key => $value) {
                $service->{$key} = $value;
            }
        }

        if (count($calls) > 0) {
            foreach ($calls as $call) {
                call_user_func_array(array($service, $call[0]), $call[1]);
            }
        }

        return $service;
    }
protected function generateService($definition)
    {
        $reflection = new \ReflectionClass($definition->getClass());
        $arguments = $definition->getArguments();
        $properties = $definition->getProperties();
        $calls = $definition->getCalls();

        if (count($arguments) > 0) {
            foreach ($arguments as &$argument) {
                if (is_string($argument)) {
                    if ('@' === $argument[0]) {
                        $serviceId = substr($argument, 1);
                        $subDefinition = $this->getDefinition($serviceId);
                        $argument = $this->generateService($subDefinition);
                    } else if (strlen($argument) > 2 && '%' === $argument[0] && '%' === substr($argument, -1)) {
                        $parameterId = substr($argument, 1, -1);
                        $argument = $this->getParameter($parameterId);
                    }
                }
            }

            $service = $reflection->newInstanceArgs($arguments);
        } else {
            $service = $reflection->newInstance();
        }

        if (count($properties) > 0) {
            foreach ($properties as $key => $value) {
                $service->{$key} = $value;
            }
        }

        if (count($calls) > 0) {
            foreach ($calls as $call) {
                call_user_func_array(array($service, $call[0]), $call[1]);
            }
        }

        return $service;
    }
Generate service instance

@param Definition $definition Service definition

@return mixed