获取子服务

该方法不设为`public`类型，目的在于规范代码，使服务方法对IDE提供友好支持。故所属的子服务类必须以`public`
类型新建方法获取。

@param string $serviceName 子服务名，不带后缀`Service`

@return Service|BaseObject|null
@throws InvalidConfigException
165123
protected function getSubService($serviceName)
    {
        if ($this->_subService[$serviceName] instanceof Service) {
            return $this->_subService[$serviceName];
        } elseif (!isset($this->_subService[$serviceName])) {
            throw new InvalidConfigException("The {$this->getId()}Service required sub service component `{$serviceName}` is not found.");
        } else {
            $uniqueName = $this->getId() . '/' . $serviceName;
            $this->_subService[$serviceName] = Yii::createObject(array_merge($this->_subService[$serviceName], [
                'service' => $this,
            ]));
            if (!$this->_subService[$serviceName] instanceof Service) {
                throw new InvalidConfigException("The required sub service component `{$uniqueName}` must return
                    an object extends `\\wocenter\\core\\Service`.");
            }
            
            Yii::trace('Loading sub service: ' . $uniqueName, __METHOD__);
            
            return $this->_subService[$serviceName];
        }
    }
180332
private function findServiceIdsByTag(ContainerBuilder $container, ServiceConfig $serviceConfig)
    {
        $tag = $serviceConfig->get(ServiceConfig::FIND_TAG);

        $serviceIds = array();

        foreach ($container->findTaggedServiceIds($tag) as $id => $services) {
            foreach ((array) $services as $service) {
                if (null === $name = $this->findName($service, $serviceConfig)) {
                    throw new \InvalidArgumentException(
                        sprintf(
                            'Service "%s" must define a name attribute like "key" or "type" for "%s" tags.',
                            $id,
                            $tag
                        )
                    );
                }

                $serviceIds[$service[$name]] = $id;
            }
        }

        return $serviceIds;
    }
1197767
public function getService( $serviceName ) {

        if ( empty( $this->services[ $serviceName ] ) ) {
            $this->services[ $serviceName ] = $this->factorySyncService( $serviceName );
        }

        if ( ! $this->services[ $serviceName ] instanceof SyncService ) {
            throw new Exception( Yii::t( 'SyncSocial', 'Component service must be instance of SyncService class' ) );
        }

        return $this->services[ $serviceName ];
    }
1229777
private function resolveParameterWithoutConfigService(ContainerInterface $container, $requestedName)
    {
        /**
         * @param ReflectionParameter $parameter
         * @return mixed
         * @throws ServiceNotFoundException If type-hinted parameter cannot be
         *   resolved to a service in the container.
         */
        return function (ReflectionParameter $parameter) use ($container, $requestedName) {
            return $this->resolveParameter($parameter, $container, $requestedName);
        };
    }
451117
public static function get($service, $default = null) {
		if($service instanceof BaseService) {
			return $service;
		}
		$serviceInstance = ArrayHelper::getValue(\App::$domain, $service, $default);
		if(!is_object($serviceInstance)) {
			throw new InvalidConfigException("Service \"$service\" not found");
		}
		return $serviceInstance;
	}
880607
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        if ($serviceLocator instanceof AbstractPluginManager) {
            $serviceLocator = $serviceLocator->getServiceLocator();
        }

        $config = $this->getConfig($serviceLocator)[$requestedName];
        $imgManService = $serviceLocator->get($config['service']);

        if (!$imgManService instanceof ImageService) {
            throw new ServiceNotCreatedException(
                sprintf(
                    'service must be a instance of ImgMan\Service\ImageService given: %s',
                    is_object($imgManService) ? get_class($imgManService) : gettype($imgManService)
                )
            );
        }

        $resourceClass = $this->getResourceClassFromConfig($config, $requestedName);

        /* @var $resource \ImgMan\Apigility\Model\ImgManConnectedResource */
        $resource = new $resourceClass($imgManService);

        if (isset($config['idName'])) {
            $resource->setIdName($config['idName']);
        }

        if (isset($config['blobName'])) {
            $resource->setBlobName($config['blobName']);
        }

        return $resource;
    }
141551
public function getConfiguredHandler($handlerName)
    {
        if (!isset($this->handlersMap[$handlerName])) {
            throw new InvalidConfigurationException("Unknown handler $handlerName");
        }

        return $this->container->get($this->handlersMap[$handlerName]);
    }
1314454
public static function service(string $service)
    {
        if (!array_key_exists($service, self::$available_services)) {
            throw (new ServiceNotFoundException(sprintf(
                '"%s" is not registered as a service.',
                $service
            )))->setServiceName($service);
        }

        $service_class = static::$available_services[$service];

        $config = static::$config['services'][$service] ?? null;

        if (is_null($config)) {
            throw (new ServiceConfigurationNotFoundException(sprintf(
                '"%s" configuration not found.',
                $service
            )))->setServiceName($service);
        }

        return $service_class::configure($config);
    }
962104
function getService(serviceName) {
		var serviceData = services[serviceName];

		if (serviceData) {
			if (!serviceData.instance) {
				serviceData.instance = serviceData.creator(application);
			}

			return serviceData.instance;
		}

		return null;
	}
1262221
protected function getConfig($name)
    {
        if (empty($name)) {
            throw new InvalidArgumentException("Service 'name' can not be empty.");
        }

        $services = $this->app['config']['df.service'];

        return array_get($services, $name);
    }
467667
public function initConnection($serviceName)
    {
        $connection = $this->clientFactory->createServiceClient($serviceName);
        $this->connectionPool[$serviceName] = $connection;

        return $this;
    }
178088
public function disconnect( $serviceName = null ) {
        $service = $this->getService( $serviceName );
        $service->disconnect();

        return ! $service->isConnected();
    }
566264
public function build($serviceConfig) {
        //“服务配置”可以是一个匿名函数
        if ($serviceConfig instanceof Closure) {
            $callback = $serviceConfig;
            $refFunc = new ReflectionFunction($callback);
            return $refFunc->getNumberOfParameters() == 1 ? $callback($this->serviceContainer) : $callback();
        }

        /*
         * 以下是数组形式的服务配置
         */

        $refClass = new ReflectionClass($serviceConfig['class']);

        //实例化
        $constructorArgs = isset($serviceConfig['constructor-args']) ? $serviceConfig['constructor-args'] : [];
        $parsedArgs = $this->parseArgs($constructorArgs);
        $serviceInstance = $refClass->newInstanceArgs($parsedArgs);

        //如果需要调用实例方法
        if (isset($serviceConfig['calls'])) {
            foreach ($serviceConfig['calls'] as $methodName => $methodArgs) {
                $refMethod = $refClass->getMethod($methodName);
                $refMethod->invokeArgs($serviceInstance, $this->parseArgs($methodArgs));
            }
        }

        return $serviceInstance;
    }
697959
protected function callRemoteService($serviceName)
    {
        if (!self::$servicesCopied) {
            self::$servicesCopied = true;
            $this->copyServicesToShop();
        }

        $oCurl = new Curl();

        $this->setParameter('service', $serviceName);

        $oCurl->setUrl($this->getTestConfig()->getShopUrl() . '/Services/service.php');
        $oCurl->setParameters($this->getParameters());

        $sResponse = $oCurl->execute();

        if ($oCurl->getStatusCode() >= 300) {
            $sResponse = $oCurl->execute();
        }

        return $this->unserializeResponse($sResponse);
    }
902378
public static function factory($className)
    {
        if (!$className || !is_string($className)) {
            exit('类名参数不正确');
        }

        $className = __NAMESPACE__ . '\\API\\' . $className . 'Api';

        if (!array_key_exists($className, self::$selfInstanceMap)) {
            $api = new $className();
            if (!$api instanceof BaseApi) {
                exit($className . ' 必须继承 BaseApi');
            }
            self::$selfInstanceMap[$className] = $api;
        }

        return self::$selfInstanceMap[$className];
    }
1259175
protected function getConfigHelper($serviceName)
    {
        $storage = new HydraTokenStorage();
        $provider = new DefaultServiceProvider($storage);

        $className = $this->getConfigHelperClassName($serviceName);

        return new $className(
            $storage,
            $provider,
            $serviceName
        );
    }
975374
public static function api($serviceName = null)
    {
        $api = self::getContainer()->get('api');

        if ($serviceName !== null) {
            return $api->service($serviceName);
        }

        return $api;
    }