Get HTTP Client

@access protected
@param string $namespace
@return object
978456
protected function getClient($namespace) {
		$path = sprintf('%s/configs/%s/%s/%s?releaseKey=%s',
			$this->conf['path'],
			$this->conf['appid'],
			$this->conf['cluster'],
			$this->conf['namespace'],
			$this->last_key);
		if ($this->conf['with_ip']) {
			$cidr = Container::getInstance()->get(CIDRmatch::class);
			foreach (swoole_get_local_ip() as $v) {
				if ($cidr->match($v, $this->conf['with_ip'])) {
					$path .= '&ip=' . $v;
					break;
				}
			}
		}
		$cli = new Client($this->conf['host'], $this->conf['port']);
		$cli->set([
			'timeout' => 1
		]);
		$cli->setDefer();
		$cli->get($path);
		return $cli;
	}
360499
public function setNamespace($namespace)
	{
	    $this->namespace = rtrim($namespace, '\\');
	    
	    // set autoload
	    if ($this->namespace) {
	        Ioc::loader()->setPsr4($this->namespace, $this->basePath . 'src');
	    }
	    
	    return $this;
	}
557054
public function createWrapper($namespace = null) {
		if (! isset($this->_wrappers[$namespace])) {
			$wrapper  = new Wrapper($this->getBackend(), $namespace);
			$lifetime = $this->getDefaultLifetime();
			
			if ($lifetime !== null) {
				$wrapper->setDefaultLifetime($lifetime);
			}
			
			$this->_wrappers[$namespace] = $wrapper;
		}
		
		return $this->_wrappers[$namespace];
	}
813589
public function getClient($identifier)
    {
        $client = $this->getClientFromPool($identifier);

        if ($client === null) {
            $client = $this->createClient($identifier);
            $this->getSession()->registerClient($client);
        }

        return $client;
    }
126406
public static function get($url, $httpHeaders = array())
    {
        //Initialize the Curl resource
        $ch = self::init($url, $httpHeaders);

        return self::processRequest($ch);
    }
900851
protected function validateNamespace($namespace)
    {
        switch ($namespace) {
            case 'ns:DNS':
                return Uuid::NAMESPACE_DNS;
                break;
            case 'ns:URL':
                return Uuid::NAMESPACE_URL;
                break;
            case 'ns:OID':
                return Uuid::NAMESPACE_OID;
                break;
            case 'ns:X500':
                return Uuid::NAMESPACE_X500;
                break;
        }

        if (Uuid::isValid($namespace)) {
            return $namespace;
        }

        throw new Exception(
            'Invalid namespace. '
            . 'May be either a UUID in string representation or an identifier '
            . 'for internally pre-defined namespace UUIDs (currently known '
            . 'are "ns:DNS", "ns:URL", "ns:OID", and "ns:X500").'
        );
    }
80468
public function get($key, $namespace = null)
    {
        return null !== $namespace ? $this->offsetGet([$namespace => $key]) : $this->offsetGet($key);
    }
1247211
public function getHttpClient()
    {
        if (!is_null($this->httpClient)) {
            return $this->httpClient;
        }

        return $this->httpClient = new Client([
            'base_uri' => $this->storageUrl(),
            'headers' => [
                'X-Auth-Token' => $this->token(),
            ],
        ]);
    }
91979
public function make(string $namespace, array $arguments = [])
    {
        $class = $this->getClassNameFromNamespace($namespace);
        /*
         * If instance of the class already created and stored into
         * stack then simply return from here
         */
        if ($this->has($class)) {
            return $this->get($class);
        }
        $reflectionClass = $this->reflection->setClass($namespace)->getReflectionClass();
        $this->throwExceptionIfNotInstantiable($namespace, $reflectionClass);

        $constructor = null;
        $constructorArgsCount = 0;
        list($constructor, $constructorArgsCount) = $this->getConstructorArgs($reflectionClass, $constructorArgsCount);

        // if class does not have explicitly defined constructor or constructor
        // does not have parameters get the new instance
        if (!isset($constructor) && is_null($constructor) || $constructorArgsCount < 1) {
            return $this[$class] = $reflectionClass->newInstance();
        }

        $dependencies = $constructor->getParameters();
        $constructorArgs = $this->createMethodArgument($dependencies, $arguments);

        return $this[$class] = $reflectionClass->newInstanceArgs($constructorArgs);
    }
482161
public static function config($namespace)
    {
        $configPath = pluginsPath($namespace.'/config.json');
        if(file_exists($configPath)) {
            return json_decode(File::get($configPath));
        }
        throw  new \Exception("No config.json file found for plugin ".$configPath);
    }
502703
private function createServiceName(string $namespace)
	{
		$parts = explode('\\', $namespace);
		foreach ($parts as $k => $part) {
			$parts[$k] = lcfirst($part);
		}
		return trim(implode('.', $parts), '.');
	}
1077494
public static function createClient(Node $api, Node $namespace) {
        $reader = new NodeReader([
            'prefixes' => [
                'wa' => 'coid://webapi.cloudobjects.io/',
                'oauth2' => 'coid://oauth2.cloudobjects.io/'
            ]
        ]);

        if (!$reader->hasType($api, 'wa:WebAPI'))
            throw new InvalidObjectConfigurationException("The API node must have the type <coid://webapi.cloudobjects.io/WebAPI>.");
        
        $baseUrl = $reader->getFirstValueString($api, 'wa:hasBaseURL');
        if (!isset($baseUrl))
            throw new InvalidObjectConfigurationException("The API must have a base URL.");
        
        $clientConfig = [ 'base_uri' => $baseUrl ];

        if ($reader->hasPropertyValue($api, 'wa:supportsAuthenticationMechanism',
                'oauth2:FixedBearerTokenAuthentication'))
            $clientConfig = self::configureBearerTokenAuthentication($api, $namespace, $reader, $clientConfig);
        else
        if ($reader->hasPropertyValue($api, 'wa:supportsAuthenticationMechanism',
                'wa:HTTPBasicAuthentication'))
            $clientConfig = self::configureBasicAuthentication($api, $namespace, $reader, $clientConfig);
        
        return new Client($clientConfig);
    }
747879
public function model($name = '', $namespace = null)
    {
        if (null === $name) {
            $namespace = $this->namespace;
        }

        $namespace = $this->resolveNamespace($namespace);
        $model = $this->model = $this->createModelInstance($namespace, $name);

        return $model;
    }
1156232
public function getFrom($namespace, $key = null, $default = null)
    {
        if (isset($_SESSION[$namespace])) {
            $oldNamespace = $this->namespace;
            $this->setNamespace($namespace);
            $result = $this->get($key, $default);
            $this->setNamespace($oldNamespace);

            return $result;
        }
        return $default;
    }
1286613
public function findNamespace($namespace)
    {
        $allNamespaces = $this->getNamespaces();
        $expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $namespace);
        $namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);

        if (empty($namespaces)) {
            $message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);

            if ($alternatives = $this->findAlternatives($namespace, $allNamespaces)) {
                if (1 == count($alternatives)) {
                    $message .= "\n\nDid you mean this?\n    ";
                } else {
                    $message .= "\n\nDid you mean one of these?\n    ";
                }

                $message .= implode("\n    ", $alternatives);
            }

            throw new CommandNotFoundException($message, $alternatives);
        }

        $exact = in_array($namespace, $namespaces, true);
        if (count($namespaces) > 1 && !$exact) {
            throw new CommandNotFoundException(sprintf("The namespace \"%s\" is ambiguous.\nDid you mean one of these?\n%s", $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))), array_values($namespaces));
        }

        return $exact ? $namespace : reset($namespaces);
    }
1024210
public function getClassesInNamespace(string $namespace)
    {
        $arrOptions = [];

        foreach (get_declared_classes() as $strName) {
            if ($this->container->get('huh.utils.string')->startsWith($strName, $namespace)) {
                $arrOptions[$strName] = $strName;
            }
        }

        asort($arrOptions);

        return $arrOptions;
    }
841536
protected static function & _namespaceGet($namespace, $name = null)
    {
        if (self::$_readable === false) {
            /**
             * @see Zend_Session_Exception
             */
            require_once 'Zend/Session/Exception.php';
            throw new Zend_Session_Exception(self::_THROW_NOT_READABLE_MSG);
        }

        if ($name === null) {
            if (isset($_SESSION[$namespace])) { // check session first for data requested
                return $_SESSION[$namespace];
            } elseif (isset(self::$_expiringData[$namespace])) { // check expiring data for data reqeusted
                return self::$_expiringData[$namespace];
            } else {
                return $_SESSION[$namespace]; // satisfy return by reference
            }
        } else {
            if (isset($_SESSION[$namespace][$name])) { // check session first
                return $_SESSION[$namespace][$name];
            } elseif (isset(self::$_expiringData[$namespace][$name])) { // check expiring data
                return self::$_expiringData[$namespace][$name];
            } else {
                return $_SESSION[$namespace][$name]; // satisfy return by reference
            }
        }
    }