Converts a service string id into Reference if needed.

@param mixed $argument the argument we may convert

@return mixed the argument which may be converted
344439
private function convertArgument($argument)
    {
        if (is_string($argument) && 0 < strlen($argument) && '@' === $argument[0]) {
            $argument = new Reference(substr($argument, 1));
        }

        return $argument;
    }
839595
private function getInjectionFuncParams(Argument $argument) : array
    {
        $dependencyIndex = (string) $argument;
        if ($this->container->getContainer()[$dependencyIndex] instanceof DependencyProvider) {
            return $this->getInjectionProviderParams($argument);
        }

        return [new Node\Arg(new Scalar\String_((string) $argument))];
    }
525619
private static function parseParams(array $arguments): string
    {
        if (0 === count($arguments)) {
            return '';
        }

        $arguments = array_map(function ($argument) {
            return beautify_parse('<argument:argument>', [
                'argument' => sprintf('"%s"', $argument),
            ]);
        }, $arguments);

        $parameters = implode(', ', $arguments);

        return sprintf('(%s)', $parameters);
    }
8208
private function createValue($object, $arguments = [])
    {

        if ($this->isInstanceOf($arguments, ConfigObject::class)) {
            $arguments = $arguments->toArray();
        }

        if (!$this->isArray($arguments)) {
            throw new ServiceManagerException(ServiceManagerException::INVALID_SERVICE_ARGUMENTS_TYPE, [$object]);
        }

        if (!$this->isString($object)) {
            return $object;
        }

        $object = $this->str($object);

        if ($object->startsWith('@')) {
            return ServiceManager::getInstance()->getService($object->trimLeft('@')->val());
        } else {
            $value = $object->val();
            if (class_exists($value)) {
                $reflection = new \ReflectionClass($value);

                return $reflection->newInstanceArgs($arguments);
            }

            return $value;
        }
    }
430715
protected function getReflectionFrom($argument)
    {
        // Method name to use.
        $reflectionMethodName = Str::camel('getreflection'.$this->target.'from');

        // Return Reflection
        return $this->{$reflectionMethodName}($argument);
    }
889834
public static function instanceFromArguments($arguments = []) {
        $arguments = array_values($arguments);
        $argumentsCount = count($arguments);
        for ($i = 0; $i < $argumentsCount; $i++) {
            if (is_object($arguments[$i]) && $arguments[$i] instanceof SharedDataInterface) {
                return $arguments[$i];
            }
        }
        return null;
    }
509840
protected function callErrorHandler($argument = null)
    {
        ob_start();
        if (is_callable($this->error)) {
            call_user_func_array($this->error, array($argument));
        } else {
            call_user_func_array(array($this, 'defaultError'), array($argument));
        }

        return ob_get_clean();
    }
200462
protected function createServiceObject(/*# string */ $id, array $arguments)
    {
        // class definition
        $def   = &$this->services[$id]['class'];
        $class = $def[0];

        // prepare constructor arguments
        $args  = empty($arguments) ?
            (isset($def[1]) ? $def[1] : []) : $arguments;

        try {
            // objects
            if (is_object($class)) {
                // closure with arguments
                if ($class instanceof \Closure) {
                    return $this->executeCallable($class, $args);

                // other object
                } else {
                    return $class;
                }

            // (pseudo) callable with arguments
            } elseif (is_array($class[0])) {
                return $this->executeCallable($class[0], $args);

            // instantiation with arguments
            } else {
                // reference value #changed
                if (false !== ($ref = $this->isReference($class))) {
                    $class = $this->getReferenceValue($ref);
                    if (is_object($class)) {
                        return $class;
                    }
                }

                return $this->constructObject($class, $args);
            }
        } catch (\Exception $e) {
            throw new LogicException($e->getMessage(), $e->getCode(), $e);
        }
    }
205128
protected function isReference($data)
    {
        // is a reference object
        if (is_object($data) && $data instanceof ReferenceAbstract) {
            return $data;

        // is string and matches reference pattern
        } elseif (is_string($data)) {
            $pat = '/^(@|%)([^\s]+)\1$/';
            $mat = []; // placeholders

            if (preg_match($pat, $data, $mat)) {
                return $mat[1] === '@' ?
                    new ServiceReference($mat[2]) :
                    new ParameterReference($mat[2]);
            }

            // parameter resolver support
            if ($this->hasResolver() &&
                $this->getResolver()->hasReference($data)) {

                list($s, $e) = $this->paramter_pattern;
                $pat = '/^' . preg_quote($s) . '([^\s]+)' . preg_quote($e). '$/';
                if (preg_match($pat, $data, $mat)) {
                    return new ParameterReference($mat[1]);
                }
            }

            return false;

        // not a match
        } else {
            return false;
        }
    }
580273
protected function processArguments($args) {
		if (is_array($args)) {
			foreach ($args as &$arg) {
				$arg = $this->processArguments($arg);
			}
			unset($arg);
			
			return $args;
		}
		
		if (is_string($args)) {
			if (preg_match('~^\[\[([a-z0-9_]+)\]\]$~i', $args, $matches)) {
				return new ServiceReference($this, $matches[1]);
			}
			
			if (preg_match('~^\{\{([a-z0-9_]+)\}\}$~i', $args, $matches)) {
				return new ConfigReference($this->getParametersConfig(), $matches[1]);
			}
		}
		
		return $args;
	}
818631
private function resolveArgument($argument)
    {
        if ($argument instanceof Definition) {
            return $this->resolveDefinition($argument);
        }

        if ($argument instanceof Reference) {
            return $this->resolveReference($argument);
        }

        if (is_array($argument)) {
            return $this->resolveArguments($argument);
        }

        return $argument;
    }
590006
protected function getServiceByArgs($args) {
		$args = $this->normalizeArgs($args);
		$id   = $this->getIdByArgs($args);
		$args = $this->processArgs($args);
			
		if (! isset($this->servicesByArgs[$id])) {
			$this->servicesByArgs[$id] = $this->initService($args);
		}

		return $this->servicesByArgs[$id];
	}
587911
private function processArguments(array $arguments)
    {
        foreach ($arguments as $k => $argument) {
            if (is_array($argument)) {
                $arguments[$k] = $this->processArguments($argument);
            } elseif ($argument instanceof Reference) {
                $defId = $this->getDefinitionId($id = (string) $argument);

                if ($defId !== $id) {
                    $arguments[$k] = new Reference($defId, $argument->getInvalidBehavior());
                }
            }
        }

        return $arguments;
    }
941524
protected function getKey($name, $arguments)
    {
        if (empty($arguments)) {
            return null;
        }
        if (is_string($arguments[0])) {
            return $arguments[0];
        } else {
            return null;
        }
    }
95015
protected function processArguments($arguments) {
		$processedArgs = [];
		
		foreach ($arguments as $key => $argument) {
			if (! isset($argument->type)) {
				throw new Exceptions\InvalidConfig('Argument definition must contain a "type" property"');
			}
			
			$type = strtolower(trim($argument->type));
			
			if ($type === 'value') {
				$processedArgs[$key] = $this->processArgumentValue($argument);
				continue;
			}
			
			if ($type === 'service') {
				$processedArgs[$key] = $this->processArgumentService($argument);
				continue;
			}
			
			if ($type === 'parameter') {
				$processedArgs[$key] = $this->processArgumentParameter($argument);
				continue;
			}
			
			throw new Exceptions\InvalidConfig('Unknown type of argument: "' . $type . '"');
		}
		
		return $processedArgs;
	}
550189
public function addCommandLineArgument($argument)
    {
        $args = (array) $this->getPhpCliArguments();
        $this->setPhpCliArguments(array_merge($args, [$argument]));

        return $this;
    }
1025422
public function get($serviceId)
    {
        if (!$this->has($serviceId)) {
            throw DiServiceNotFound::createFromServiceId($serviceId);
        }

        if (!isset($this->services[$serviceId])) {
            $this->services[$serviceId] = $this->getServiceFromFactory($serviceId);
        }

        return $this->services[$serviceId];
    }