Access to the Subbly Api.

@param null|string $serviceName The name of the service (optional)

@return \Subbly\Api\Api|\Subbly\Api\Service\Service

@api
975374
public static function api($serviceName = null)
    {
        $api = self::getContainer()->get('api');

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

        return $api;
    }
1359229
public function createForService($serviceName) {
		if ($this->_basePath === null) {
			throw new ConfigError('Base path was not given');
		}
		
		$filename = $this->_filenameTemplate;
		
		if (strpos($filename, self::PATTERN_SERVICE) !== false) {
			$filename = str_replace(self::PATTERN_SERVICE, $serviceName, $filename);
		}
		
		if (strpos($filename, self::PATTERN_DATE) !== false) {
			$filename = str_replace(self::PATTERN_DATE, date($this->_dateFormat), $filename);
		}
		
		$path = $this->_basePath;
		
		if ($this->_separateDirs) {
			$path .= DIRECTORY_SEPARATOR . $serviceName;
			
			if ((! file_exists($path) || ! is_dir($path)) && ! mkdir($path)) {
				throw new NoDirectory('Directory does not exists and unable to create: "' . $path . '"');
			}
		}
		
		$path .= DIRECTORY_SEPARATOR . $filename;
		
		if (isset($this->_loggers[$serviceName])) {
			return $this->_loggers[$serviceName];
		}
		
		$adapter = $this->getCreateCallback()->__invoke($path);
		$logger  = new Logger($adapter);
		
		$this->_loggers[$serviceName] = $logger;
		return $logger;
	}
1022512
public function setServiceName($serviceName)
    {
        $allowedValues = $this->getServiceNameAllowableValues();
        if (!in_array($serviceName, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'serviceName', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['serviceName'] = $serviceName;

        return $this;
    }
173964
private static function determineService($appName = null) : ServiceLocator
    {
        if ($appName === null) {
            $service = !isset(self::$serviceCollections)
                ? new ServiceLocator(new App())
                : self::getDefault();
            return $service;
        }

        return self::getService($appName);
    }
254611
final public function get(string $name)
    {
        $service_selected = null;
        foreach ($this->services as $one => $val) {
            if ($val['name'] === $name) {
                if (!in_array($val['content']->status, array("enabled", "disabled"))) {
                    throw new Server500(new \ArrayObject(array("explain" =>
                        "Undefined status [ ".$val['content']->status." ] for ".$val['name']." service",
                        "solution" => "Please set the status [disabled] or [enabled]")));
                }
                if ($val['content']->status == "disabled") {
                    throw new Server500(new \ArrayObject(array("explain" =>
                        "The service [ ".$val['name']." ] is currently disabled ",
                        "solution" => "Please set the status [enabled] to enable the service")));
                }
                $i = $val['content']->namespace;
                $container = FrameworkContainer::getInstance();
                return ($container->get($i));
            }
        }

        throw new Server500(new \ArrayObject(array("explain" =>
            "Undefined service : $name", "solution" => "Please register the [$name] service")));
    }
376033
public <T> T getService(String serviceName) {
    T service = findService(serviceName, true);
    if (service == null) {
      throw new IllegalArgumentException(format("No service found named \"%s\"", serviceName));
    }

    return service;
  }
978814
protected function loadConfig($serviceName)
    {
        if (!empty($this->config[$serviceName])) {
            return $this->config[$serviceName];
        } else {
            throw new OAuthServiceException('No configuration for ' . $serviceName . ' service');
        }
    }
35444
public function getServiceList(string $serviceName, ...$params)
    {
        $httpClient = new Client();
        $url        = $this->getDiscoveryUrl($serviceName);
        $result     = $httpClient->get($url)->getResult();
        $services   = json_decode($result, true);

        // 数据格式化
        $nodes = [];
        foreach ($services as $service) {
            if (!isset($service['Service'])) {
                App::warning("consul[Service] 服务健康节点集合，数据格式不不正确，Data=" . $result);
                continue;
            }
            $serviceInfo = $service['Service'];
            if (!isset($serviceInfo['Address'], $serviceInfo['Port'])) {
                App::warning("consul[Address] Or consul[Port] 服务健康节点集合，数据格式不不正确，Data=" . $result);
                continue;
            }
            $address = $serviceInfo['Address'];
            $port    = $serviceInfo['Port'];

            $uri     = implode(":", [$address, $port]);
            $nodes[] = $uri;
        }

        return $nodes;
    }
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);
    }
1179399
public function getServiceMethod($methodName)
    {
        return $this->getService($this->getServiceName($methodName)) instanceof Service ? $this->getService($this->getServiceName($methodName))->getMethod($methodName) : null;
    }
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;
	}
365800
public function getServiceDump($serviceName)
    {
        $this->assertServiceExist($serviceName);

        return [
            'class'      => get_class($this->services[$serviceName]['definition']),
            'arguments'  => $this->getRegisterServiceArguments($serviceName)
        ];
    }
579548
private function instantiateService($serviceName)
    {
        // Make sure service is registered
        if (!$this->registeredServices->keyExists($serviceName)) {
            throw new ServiceManagerException(ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND, [$serviceName]);
        }

        // Get service config from registered services array
        $config = $this->registeredServices->key($serviceName);

        // Check circular referencing
        if ($this->references->keyExists($serviceName)) {
            throw new ServiceManagerException(ServiceManagerException::SERVICE_CIRCULAR_REFERENCE, [$serviceName]);
        }

        // Set service name reference for circular referencing checks
        $this->references->key($serviceName, $serviceName);

        // Compile ConfigObject into ServiceConfig
        $configCompiler = new ConfigCompiler($serviceName, $config, $this->parameters);
        $this->compiledConfig->key($serviceName, $configCompiler->compile());

        /**
         * @var $config ServiceConfig
         */
        $config = $this->compiledConfig->key($serviceName);

        // Construct service container and get service instance
        $serviceCreator = new ServiceCreator($config);
        $service = $serviceCreator->getService();

        // Unset service name reference
        $this->references->removeKey($serviceName);

        // Store instance if this service has a CONTAINER scope
        if ($config->getScope() == ServiceScope::CONTAINER) {
            $this->instantiatedServices->key($serviceName, $service);
        }

        return $service;
    }
772871
public function getPath($serviceName)
    {
        if (in_array($serviceName, $this->services)) {
            return str_replace('_', '/', $serviceName);
        } else {
            $services = implode(', ', $this->services);
            throw new \Exception("Service \"{$serviceName}\" is not one of: {$services}");
        }
    }
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 ];
    }
386888
public function getService(string $serviceKey): DIServiceWrapper
    {
        /** @var DIServiceWrapper $service */
        foreach ($this->getServices() as $service) {
            if ($service->getKey() === $serviceKey) {
                return $service;
            }
        }
        throw new MissingServiceException("Service $serviceKey not found");
    }
973468
protected function getServiceIp(string $serviceName, bool $force = false): string
    {
        if (!isset($this->serviceIps[$serviceName]) || $force) {
            $serviceIp = $this->discovery->discover($serviceName);
            $this->serviceIps[$serviceName] = $serviceIp;
        }

        return $this->serviceIps[$serviceName];
    }