Get service by name

@param string $name
@param array $params

@return IService|null
@throws InvalidConfigException
547288
private function getService(string $name, array $params = []): ?IService
    {
        if (array_key_exists($name, $this->servicesInstances)) {
            return $this->servicesInstances[$name];
        }

        $serviceConfig = $this->getServiceConfig($name);
        if ($serviceConfig === null) {
            return null;
        }

        $class = $serviceConfig['class'];
        unset($serviceConfig['class']);
        $serviceConfig = array_merge($serviceConfig, isset($params[0]) && \is_array($params[0]) ? $params[0] : []);

        if (!class_exists($class)) {
            throw new InvalidConfigException(sprintf('Class %s does not exists', $class));
        }

        if (\is_subclass_of($class, BaseModelService::class)
            || \is_subclass_of($class, BaseControllerService::class)
        ) {
            $service = new $class($this, $serviceConfig);
        } else {
            $service = new $class($serviceConfig);
        }

        if (!($service instanceof IService)) {
            throw new InvalidConfigException('Service class must implement `' . IService::class . '`.');
        }

        return $this->servicesInstances[$name] = $service;
    }
794441
public function getWebservice($name)
    {
        if (!isset($this->_webservices[$name])) {
            list($pluginName) = pluginSplit(App::shortName(get_class($this), 'Webservice/Driver'));

            $webserviceClass = implode('.', array_filter([$pluginName, Inflector::camelize($name)]));

            $webservice = $this->_createWebservice($webserviceClass, [
                'endpoint' => $name,
                'driver' => $this,
            ]);

            $this->_webservices[$name] = $webservice;
        }

        return $this->_webservices[$name];
    }
222536
public function getProvider(string $name) : string
    {
        $providers = $this->getProviders();
        if (!in_array($name, array_keys($providers))) {
            throw new InvalidArgumentException("Provider for [$name] is not configured");
        }

        return $providers[$name];
    }
678469
protected function makeService($name)
    {
        $config = $this->getConfig($name);

        // First we will check by the service name to see if an extension has been
        // registered specifically for that service. If it has we will call the
        // Closure and pass it the config allowing it to resolve the service.
        if (isset($this->extensions[$name])) {
            return call_user_func($this->extensions[$name], $config, $name);
        }

        $config = $this->getDbConfig($name);
        $type = $config['type'];

        // Next we will check to see if a type extension has been registered for a service type
        // and will call the factory Closure if so, which allows us to have a more generic
        // resolver for the service types themselves which applies to all services.
        if (isset($this->types[$type])) {
            return $this->types[$type]->make($name, $config);
        }

        throw new InvalidArgumentException("Unsupported service type '$type'.");
    }
505119
protected function loadCollector($name, array $params = null) {
		$locator = $this->getCollectorsLocator();
		
		try {
			return $locator->get(ucfirst($name), $params);
		} catch (Exception $exception) {
			$this->pushException($exception);
		}
	}
995872
protected function getSymfonyFormFromParams($params, $name, $throwException = false)
    {
        $sfForm = $this->getParam($params, $name);

        if (null === $sfForm && false === $throwException) {
            return null;
        }

        if (!$sfForm instanceof SymfonyForm) {
            throw new \InvalidArgumentException(
                sprintf(
                    "%s parameter must be an instance of " .
                    "\Symfony\Component\Form\Form, instance of %s found",
                    $name,
                    is_object($sfForm) ? get_class($sfForm) : gettype($sfForm)
                )
            );
        }

        return $sfForm;
    }
525522
public function getParameter($name)
    {
        if (!array_key_exists($name, $this->config)) {
            throw new \InvalidArgumentException(sprintf(
                'Parameter "%s" has not been registered',
                $name
            ));
        }

        return $this->config[$name];
    }
429360
public function find(string $name)
    {
        if (! \array_key_exists($name, $this->keyMap)) {
            throw new InvalidArgumentException("Name [{$name}] is not available.");
        }

        return $this->controls[$this->keyMap[$name]];
    }
677275
public function get($name)
    {
        if (!$paramConfig = $this->methodRequirements[$name]) {
            return;
        }

        $config = new Credential($name, $paramConfig);

        if (true === $config->required && !($this->getRequest()->request->has($name))) {
            throw new BadRequestUserException(
                $this->formatError($name, false, 'The parameter must be set')
            );
        }

        $param = $this->getRequest()->request->get($name);

        if (false === $config->nullable && !$param) {
            throw new BadRequestUserException(
                $this->formatError($name, $param, 'The parameter cannot be null')
            );
        }

        if (($config->default && $param === $config->default
        || ($param === null && true === $config->nullable)
        || (null === $config->requirements))) {
            return $param;
        }

        $this->validateParam($config, $param);

        return $param;
    }
142693
public function getByName($name)
    {
        if (isset($this->searchServices[$name])) {
            return $this->searchServices[$name];
        } else {
            throw new UnknowSearchNameException($name);
        }
    }
1316211
protected function getJoinByName($name): Join
    {
        $joins = $this->joins();

        if (!isset($joins[$name])) {
            throw new InvalidConfigException('Join named "' . $name . '" does not exist.');
        }

        return $joins[$name];
    }
234812
public static function getService($name = '')
    {
        if ($name == '') return $_SERVER;
        return (isset($_SERVER[$name])) ? strip_tags($_SERVER[$name]) : '';
    }
366127
public static function get($name, array $args = [])
    {
        if (!isset(self::$services[$name])) {
            throw new ServiceNotFoundException(sprintf('Service "%s" does not exist.', $name));
        }

        $instance = self::$services[$name]->resolve(self::getInstance(), $args);

        if ($instance instanceof ContainerAwareInterface) {
            $instance->setContainer(self::getInstance());
        }

        return $instance;
    }
891804
private function getNamedQueryConfiguration($name)
    {
        if (array_key_exists($name, $this->namedQueryConfiguration)) {
            return $this->namedQueryConfiguration[$name];
        }

        throw new InvalidArgumentException(
            "Could not find query configuration named '{$name}'"
        );
    }
421382
protected function createServiceConfig(string $name): array
    {
        $config = [];
        if ($this->has($name)) {
            $config = $this->config[$name];
        }

        $class = $name;

        if (isset($config['use'])) {
            if (!is_string($config['use'])) {
                throw new Exception\InvalidConfiguration('use must be a string for service '.$name);
            }

            $class = $config['use'] = $this->getEnv($config['use']);
        }

        if (preg_match('#^\{([^{}]+)\}$#', $class)) {
            $config = array_merge($this->getServiceDefaults(), $config);

            return $config;
        }

        $config = $this->mergeServiceConfig($name, $class, $config);

        if (isset($config['use'])) {
            $class = $config['use'] = $this->getEnv($config['use']);
        }

        if (!class_exists($class)) {
            throw new Exception\InvalidConfiguration('class '.$class.' is either not a class or can not be found');
        }

        return $config;
    }
1046125
public function findServiceByName($name)
    {
        foreach ($this->services as $service) {
            if ($service->getName() === $name) {
                return $service;
            }
        }

        throw new \OutOfBoundsException(sprintf('There is no service named %s', $name));
    }
785613
public function getBotConfig($name = null)
    {
        $name = $name ?: $this->getDefaultBot();

        $bots = $this->getConfig('bots');
        if (!is_array($config = array_get($bots, $name)) && !$config) {
            throw new InvalidArgumentException("Bot [$name] not configured.");
        }

        $config['bot'] = $name;

        return $config;
    }