Initialize service by ID

@param  string $id   ID of service
@param  array  $args Arguments for constructor of service
@return mixed
@throws Exceptions\ServiceNotFound
197539
protected function initService($id, array $args = null) {
		$reflection = $this->getReflectionById($id);
		
		if ($reflection === null) {
			throw new Exceptions\ServiceNotFound('Unable to found the service "' . $id . '"');
		}
		
		if ($args === null) {
			return $reflection->newInstance();
		}

		return $reflection->newInstanceArgs($args);
	}
1253617
public function reset($args = null) {
		if ($args === null) {
			$this->service = null;
			return;
		}
		
		$args = $this->normalizeArgs($args);
		$id   = $this->getIdByArgs($args);
		
		unset($this->servicesByArgs[$id]);
	}
1146896
public function getSubService($id, $interface = null)
    {
        if (! isset($this->subServices[$id])) {
            if ($this->hasOption($id)) {
                $service = $this->buildService($this->getOption($id), $interface);
                if ($service) {
                    $this->subServices[$id] = $service;
                } else {
                    throw new ServiceNotFoundException($id);
                }
            } else {
                throw new ServiceNotFoundException($id);
            }
        }
        return $this->subServices[$id];
    }
537776
public function getServiceNameById($id)
    {
        $map = $this->getServiceIdNameMap();
        if (array_key_exists($id, $map)) {
            return $map[$id];
        }

        return null;
    }
1301942
public function add($id, $entry, array $args = [])
    {
        $this->container[$id] = new Service($entry, $args);

        return $this;
    }
880546
private function getServiceOrParameter($id)
    {
        if (array_key_exists($id, $this->aliases)) {
            return $this->offsetGet($this->aliases[$id]);
        }

        if (array_key_exists($id, $this->values)) {
            return $this->values[$id];
        }

        if (array_key_exists($id, $this->definitions)) {
            return $this->values[$id] = $this->build($this->definitions[$id]);
        }

        throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id));
    }
1040195
public function addService(DataTableHandlerInterface $service, string $id = null)
    {
        $service_id = $id ?? $service::ID;

        if ($service_id !== null) {
            $this->services[$service_id] = $service;
        }
    }
731058
public function get($id)
    {
        foreach ($this->data as $host) {
            if ($host->getId() === $id) {
                return $host;
            }
        }

        throw new ResourceNotFoundException(sprintf('Service "%s" not found.', $id));
    }
313905
protected function serviceFromDefinition($id, $args)
    {
        // create the service object
        $service = $this->createServiceObject($id, $args);

        // run predefined methods if any
        $this->runDefinedMethods($id, $service);

        // decorate the service if DecorateExtension loaded
        $this->decorateService($service);

        return $service;
    }
584776
public function delete($id, $args = [])
    {
        $wpcli_args = buildCLIArgs(
            ['force'],
            $args
        );

        array_unshift($wpcli_args, $id);

        $this->drivers->getDriver()->wpcli('comment', 'delete', $wpcli_args);
    }
898557
public function addMetaBox($id, $args)
    {
        $box = new MetaBox($id, $this->name, $args);

        return $this;
    }
1022978
public function set($id, $service)
    {
        $id = strtolower($id);

        if ('service_container' === $id) {
            throw new InvalidArgumentException('You cannot set service "service_container".');
        }

        if (isset($this->aliases[$id])) {
            unset($this->aliases[$id]);
        }

        $this->services[$id] = $service;

        if (null === $service) {
            unset($this->services[$id]);
        }

        if (isset($this->privates[$id])) {
            if (null === $service) {
                @trigger_error(sprintf('Unsetting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
                unset($this->privates[$id]);
            } else {
                @trigger_error(sprintf('Setting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0. A new public service will be created instead.', $id), E_USER_DEPRECATED);
            }
        }
    }
190659
public function get($id, $args = [])
    {
        $comment = get_comment($id);

        if (! $comment) {
            throw new UnexpectedValueException(sprintf('[W601] Could not find comment with ID %d', $id));
        }

        return $comment;
    }
286001
protected function initService(array $args = null) {
		if ($args === null) {
			return call_user_func($this->callback);
		}
		
		return call_user_func_array($this->callback, $args);
	}
1012666
public function offsetGet($id)
    {
        if (!isset($this->keys[$id])) {
            $tmpId = ucfirst($id);
            if (!isset($this->values['serviceProviders'][$tmpId])) {
                throw new UnknownIdentifierException($id);
            }

            $provider = $this->values['serviceProviders'][$tmpId][0];
            $provider = new $provider($this);
            $provider->register();
        }

        if (
            isset($this->raw[$id])
            || !is_object($this->values[$id])
            || isset($this->protected[$this->values[$id]])
            || !method_exists($this->values[$id], '__invoke')
        ) {
            return $this->values[$id];
        }

        if (isset($this->factories[$this->values[$id]])) {
            return $this->values[$id]($this);
        }

        $raw = $this->values[$id];
        $val = $this->values[$id] = $raw($this);
        $this->raw[$id] = $raw;

        $this->frozen[$id] = true;

        return $val;
    }
359738
private function parseDefinition($id, $service)
    {
        if (is_string($service) && 0 === strpos($service, '@')) {
            $this->container->setAlias($id, substr($service, 1));

            return;
        }

        if (!is_array($service)) {
            throw new InvalidArgumentException(sprintf('A service definition must be an array or a string starting with "@" but %s found for service "%s". Check your YAML syntax.', gettype($service), $id));
        }

        if (isset($service['alias'])) {
            $public = !array_key_exists('public', $service) || (bool) $service['public'];
            $this->container->setAlias($id, new Alias($service['alias'], $public));

            return;
        }

        if (isset($service['parent'])) {
            $definition = new DefinitionDecorator($service['parent']);
        } else {
            $definition = new Definition();
        }

        if (isset($service['class'])) {
            $definition->setClass($service['class']);
        }

        if (isset($service['scope'])) {
            $definition->setScope($service['scope']);
        }

        if (isset($service['synthetic'])) {
            $definition->setSynthetic($service['synthetic']);
        }

        if (isset($service['synchronized'])) {
            $definition->setSynchronized($service['synchronized'], 'request' !== $id);
        }

        if (isset($service['lazy'])) {
            $definition->setLazy($service['lazy']);
        }

        if (isset($service['public'])) {
            $definition->setPublic($service['public']);
        }

        if (isset($service['abstract'])) {
            $definition->setAbstract($service['abstract']);
        }

        if (isset($service['factory'])) {
            if (is_string($service['factory'])) {
                if (strpos($service['factory'], ':') !== false && strpos($service['factory'], '::') === false) {
                    $parts = explode(':', $service['factory']);
                    $definition->setFactory(array($this->resolveServices('@'.$parts[0]), $parts[1]));
                } else {
                    $definition->setFactory($service['factory']);
                }
            } else {
                $definition->setFactory(array($this->resolveServices($service['factory'][0]), $service['factory'][1]));
            }
        }

        if (isset($service['factory_class'])) {
            $definition->setFactoryClass($service['factory_class']);
        }

        if (isset($service['factory_method'])) {
            $definition->setFactoryMethod($service['factory_method']);
        }

        if (isset($service['factory_service'])) {
            $definition->setFactoryService($service['factory_service']);
        }

        if (isset($service['file'])) {
            $definition->setFile($service['file']);
        }

        if (isset($service['arguments'])) {
            $definition->setArguments($this->resolveServices($service['arguments']));
        }

        if (isset($service['properties'])) {
            $definition->setProperties($this->resolveServices($service['properties']));
        }

        if (isset($service['configurator'])) {
            if (is_string($service['configurator'])) {
                $definition->setConfigurator($service['configurator']);
            } else {
                $definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1]));
            }
        }

        if (isset($service['calls'])) {
            if (!is_array($service['calls'])) {
                throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s". Check your YAML syntax.', $id));
            }
            foreach ($service['calls'] as $call) {
                if (isset($call['method'])) {
                    $method = $call['method'];
                    $args = isset($call['arguments']) ? $this->resolveServices($call['arguments']) : array();
                } else {
                    $method = $call[0];
                    $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
                }
                $definition->addMethodCall($method, $args);
            }
        }

        if (isset($service['tags'])) {
            if (!is_array($service['tags'])) {
                throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s". Check your YAML syntax.', $id));
            }

            foreach ($service['tags'] as $tag) {
                if (!is_array($tag)) {
                    throw new InvalidArgumentException(sprintf('A "tags" entry must be an array for service "%s". Check your YAML syntax.', $id));
                }
                if (!isset($tag['name'])) {
                    throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s".', $id));
                }
                $name = $tag['name'];
                unset($tag['name']);
                foreach ($tag as $attribute => $value) {
                    if (!is_scalar($value) && null !== $value) {
                        throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s". Check your YAML syntax.', $id, $name, $attribute));
                    }
                }
                $definition->addTag($name, $tag);
            }
        }

        if (isset($service['decorates'])) {
            $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
            $definition->setDecoratedService($service['decorates'], $renameId);
        }

        $this->container->setDefinition($id, $definition);
    }
1018476
public static function oneById($serviceName, $id)
	{
		if(!self::has($serviceName)) {
			return null;
		}
		/** @var ReadOneInterface $serviceInstance */
		$serviceInstance = self::get($serviceName);
		try {
			$result = $serviceInstance->oneById($id);
		} catch (NotFoundHttpException $e) {
			$result = null;
		}
		return $result;
	}