Initialize service by ID

@param  string $id   ID of service
@param  array  $args Arguments for constructor of service
@return mixed
@throws Exceptions\ServiceNotFound
555774
protected function initService($id, array $args = null) {
		$method = sprintf($this->methodNameTemplate, lcfirst($id));
		
		if (! method_exists($this, $method)) {
			throw new Exceptions\ServiceNotFound('Unable to found the service "' . $id . '"');
		}
		
		if ($args === null) {
			return $this->$method();
		}
		
		return call_user_func_array([$this, $method], $args);
	}
1270887
public function get($id, $args = [])
    {
        if (is_numeric($id) || ! isset($args['by'])) {
            $type = 'ID';
        } else {
            $type = $args['by'];
        }

        $user = get_user_by($type, $id);

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

        return $user;
    }
610924
public function getService(string $id)
    {
        if ($this->serviceContainer->has($id)) {
            return $this->serviceContainer->get($id);
        }

        if ($this->reversibleLocator->has($id)) {
            return $this->reversibleLocator->get($id);
        }

        if (isset($this->serviceContainer->getRemovedIds()[$id])) {
            throw new ServiceNotFoundException($id, null, null, [], sprintf('The "%s" service is private and cannot be accessed by reference. You should either make it public, or tag it as "%s".', $id, $this->tagName));
        }

        // will throw a ServiceNotFoundException
        $this->serviceContainer->get($id);
    }
1183150
public function getService($id) {
            if (!isset($this->services[$id])) {
                // TODO: execption
                return null;
            }
            if (is_string($this->services[$id])) {
                $this->services[$id] = $this->container->get($this->services[$id]);
            }

            return $this->services[$id];
        }
791910
public function hasInitialized($id, $args = null) {
		if (isset($args[2])) {
			$args = func_get_args();
			array_shift($args);
		}
		
		return $this->getDefinition($id)->hasInitialized($args);
	}
1049473
public function getService(string $id, $thrErr = false)
    {
        $id = $this->resolveAlias($id);

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

        if ($thrErr) {
            throw new \InvalidArgumentException("The service '$id' was not found, has not been registered!");
        }

        return null;
    }
896584
public function command($command, $args = [], $id = null)
    {
        $target = Router::getInstance()->getTarget($command);
        $fn = function () use ($target) {
            return $target->run();
        };

        return $this->call($fn, $args, $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];
    }
300994
public function update($id, $args = [])
    {
        $bin          = '';
        $command_args = sprintf(
            '--no-defaults --no-auto-rehash --host=%1$s --user=%2$s --database=%3$s --execute=%4$s',
            DB_HOST,
            DB_USER,
            DB_NAME,
            escapeshellarg(sprintf(
                'SET autocommit = 0; SET unique_checks = 0; SET foreign_key_checks = 0; SOURCE %1$s; COMMIT;',
                $args['path']
            ))
        );

        $old_pwd = getenv('MYSQL_PWD');
        putenv('MYSQL_PWD=' . DB_PASSWORD);

        // Support Windows.
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
            $bin = '/usr/bin/env ';
        }

        // Import DB via mysql-cli.
        $proc = proc_open(
            "{$bin}mysql {$command_args}",
            array(
                1 => ['pipe', 'w'],
                2 => ['pipe', 'w'],
            ),
            $pipes
        );

        $stdout = trim(stream_get_contents($pipes[1]));
        $stderr = trim(stream_get_contents($pipes[2]));
        fclose($pipes[1]);
        fclose($pipes[2]);
        $exit_code = proc_close($proc);
        putenv('MYSQL_PWD=' . $old_pwd);

        // Sometimes the error message is in stderr.
        if (! $stdout && $stderr) {
            $stdout = $stderr;
        }

        if ($exit_code || strpos($stdout, 'Warning: ') === 0 || strpos($stdout, 'Error: ') === 0) {
            throw new RuntimeException(
                sprintf(
                    "[W607] Could not import database in method %1\$s(): \n\n%2\$s.\n(%3\$s)",
                    debug_backtrace()[1]['function'],
                    $stdout,
                    $exit_code
                )
            );
        }

        /*
         * clear the cache after restoration - this is probably only necessary
         * because of some kind of global state issue - the WPCLI driver doensn't
         * need it. There is some discussion about it here:
         *
         * https://github.com/paulgibbs/behat-wordpress-extension/pull/150
         */
        \wp_cache_flush();
    }
406917
protected function instantiateService(string $id, array $arguments)
    {
        if (isset($this->instances[$id])) {
            return $this->instances[$id];
        }

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

        if (isset($this->callableDefinitions[$id])) {
            $this->factories[$id] = $this->createServiceFactoryFromCallable($this->callableDefinitions[$id]);

            return $this->invokeFactory($id, $arguments);
        }

        $class = $this->classDefinitions[$id] ?? $id;
        if ($class !== $id) {
            // Recursive call allows to bind contract to contract.
            return $this->saveShared($id, $this->instantiateService($class, $arguments));
        }
        if (!class_exists($class)) {
            throw new NotFoundException($id, $this->resolving);
        }
        $this->factories[$id] = $this->createServiceFactoryFromClass($class);

        return $this->invokeFactory($id, $arguments);
    }
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));
    }
1036396
public function initialized($id)
    {
        $id = $this->normalizeId($id);

        if (isset($this->privates[$id])) {
            @trigger_error(sprintf('Checking for the initialization of the "%s" private service is deprecated since Symfony 3.4 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
        }

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

        if ('service_container' === $id) {
            return false;
        }

        return isset($this->services[$id]);
    }
1083644
public function select($id = null)
    {
        if (!is_array($id) || !isset($id['service']) || !isset($id['method']) || empty($id['service']) || empty($id['method'])) {
            throw new \InvalidArgumentException('Invalid id argument. Must be array and containing at least service and method property.');
        }

        $serviceName = $id['service'];
        if (!isset($this->services[$serviceName])) {
            throw new \InvalidArgumentException("Service '$serviceName' is not registered in StorageProvider.");
        }

        $method = $id['method'];
        if (!empty($this->services[$serviceName]['methods']) && !in_array($method, $this->services[$serviceName]['methods'])) {
            throw new \InvalidArgumentException("Method '$method' is not registered in StorageProvider for service '$serviceName'.");
        }

        $service = $this->container->get($serviceName);
        $callable_with_arguments = array($service, $method, isset($id['arguments']) ? $id['arguments'] : null);

        return new StorageSelection($callable_with_arguments);
    }
287445
public function activate($id, $args = [])
    {
        $plugin = $this->drivers->getDriver()->getPlugin($id);

        if (! $plugin) {
            throw new UnexpectedValueException("[W608] Cannot find the plugin: {$id}.");
        }

        $this->update($plugin, ['status' => 'activate']);
    }
252336
public function getServiceOptions($id)
	{
	    $id = $this->normalizeServiceId($id);
	    
	    if(!isset($this->services[$id])){
	        throw new Exception\ServiceNotFoundException(
                sprintf('Service ID "%s" does not exist', $id)
	        );
	    }
	    
	    return $this->services[$id]['options'];
	}
656928
public function setService($id)
    {
        $id = filter_var($id, FILTER_SANITIZE_NUMBER_INT);
        if (empty($id)) {
            throw new InternalServerErrorException('No service id provided.');
        }

        if (empty($this->service = ServiceManager::getServiceNameById($id))) {
            throw new InternalServerErrorException('No alternate db service found with id ' . $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;
    }