@param string $method
@param string $path
@param array  $options

@return array
340710
private function request($method, $path = '', array $options = [])
    {
        $options['headers'] = array_merge(
            [
                'User-Agent' => $this->app_client,
            ],
            isset($options['headers']) ? $options['headers'] : []
        );

        try {
            $response = $this->client->request($method, $this->host.$this->prefix.$path, $options);
        } catch (\Exception $e) {
            throw $this->wrapException($e);
        }

        $content = $response->getBody()->getContents();
        $content = $this->detector->detect($content);

        return $content;
    }
1194471
protected static function createBody($options, $method)
    {
        return ('GET' !== $method) ? is_array($options) ? http_build_query($options) : ltrim($options, '&') : null;
    }
627959
public static function get($path, $options = array()) {
    $requestOptions = array(
      "path" => $path,
      "method" => "GET"
    );

    if (!empty($options["sign"])) {
      $requestOptions["sign"] = $options["sign"];
    }

    return self::request($requestOptions);
  }
625913
protected function buildRequest(string $method, string $url, array $options = []): array
    {
        if ($this->forcedAcceptJson) {
            $this->headers['accept'] = 'application/json';
        }
        if (count($this->headers) > 0) {
            if (!array_key_exists(RequestOptions::HEADERS, $options) || !is_array($options[RequestOptions::HEADERS])) {
                $options[RequestOptions::HEADERS] = [];
            }
            foreach ($this->headers as $headerName => $headerValue) {
                $options[RequestOptions::HEADERS][$headerName] = $headerValue;
            }
        }

        $options = $this->addAuthHeader($options);

        return [
            self::OPTION_METHOD => $method,
            self::OPTION_URL => $this->buildUrl($url),
            self::OPTION_OPTIONS => $options
        ];
    }
287374
protected function sendRequest($url, $method = 'get', array $options = [])
    {
        return $this->send(
          new Request($method, $url),
          $this->client,
          $options
        );
    }
407221
public function match($route, $method = 'GET', $options = [])
    {
        $this->method = $method;
        $this->options = $options;
        $this->count = 0;

        // Init some data
        $this->buildRouteMaps()
            ->buildTree();

        // Match
        $segments = explode('/', RouteHelper::sanitize($route));

        $routeItem = $this->matchSegment($segments, $this->tree);

        if (!$routeItem) {
            return false;
        }

        $routeItem->setVariables(array_merge($routeItem->getVariables(), $this->vars));

        return $routeItem;
    }
877175
public function method($method = null, $path = '/')
    {
        $parameters = array();

        $parameters['path'] = $path;

        if($method)
            $parameters['method'] = $method;

        $route = $this->factory->createRoute($this, null, $parameters);

        $this->addRoute($route);

        return $route;
    }
1013009
public function execute($method, array $options = [], array $arguments = []) {
        $params = [];

        if (count($options) > 0) {
            $params['options'] = $options;
        }

        if (count($arguments) > 0) {
            $params['arguments'] = $arguments;
        }

        $result = $this->api->request(
            $method,
            $params
        );

        if (!array_key_exists('success', $result)) {
            throw new RuntimeException('Missing success status');
        }

        if (!is_bool($result['success']) || $result['success'] === false) {
            throw new RuntimeException('Command failed');
        }

        if (!array_key_exists('output', $result)) {
            throw new RuntimeException('Missing output');
        }

        if (!is_array($result['output'])) {
            throw new RuntimeException('Invalid output');
        }

        return $result['output'];
    }
458040
public function map($optionsOrMethod, $path, $handler)
    {
        $this->options = $this->defaultOptions($optionsOrMethod);
        $this->path = $path;
        $this->handler = $handler;
        return $this;
    }
1249794
public function getRequest($method, $url, array $options = [])
    {
        return $this->createRequest($method, $url, null, $options);
    }
1179912
protected function request($uri, $method = 'get', $options = array())
    {
        $this->clear();

        if (! in_array(strtolower($method), $this->methods)) {
            return $this->setError('Unknown request method: ' . $method);
        }

        $isAuthorized = $this->accessToken || $this->token ||
                        ($this->username && $this->password);

        if (! $isAuthorized) {
            return $this->setError('Please provide token or username and password');
        }

        // if uri is passed as array, create uri string from uri parts
        if (is_array($uri)) {
            $uri = implode('/', $uri);
        }

        // api request url
        $url = $this->endpoint . $uri;

        $handle = curl_init();

        if ($this->accessToken) {
            // Access token is used in OAuth2 flow
            $url .= '?access_token=' . $this->accessToken;
        } else if ($this->token) {
            // Auth token is taken from PG account
            $url .= '?auth_token=' . $this->token;
        } else {
            // if using username and password - pass them as curl option
            curl_setopt($handle, CURLOPT_USERPWD, $this->username . ':' . $this->password);
        }

        curl_setopt($handle, CURLOPT_URL, $url);
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($handle, CURLOPT_CUSTOMREQUEST, strtoupper($method));
        curl_setopt($handle, CURLOPT_HTTPHEADER, array(
            'Content-type: multipart/form-data;',
        ));

        // if request has additional options - add them to request
        if (! empty($options)) {

            // extract files, pass them separately
            $files = array();
            foreach ($options as $key => $value) {
                if (! empty($value) && ! is_array($value) && $value[0] === '@') {
                    $files[$key] = $this->toCurlFile($value);
                    unset($options[$key]);
                }
            }

            $data = $files;

            if (! empty($options)) {
                // original API requires data to be in json format
                $data = array_merge($data, array(
                    'data' => json_encode($options),
                ));
            }

            curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
        }

        $response = curl_exec($handle);

        if (curl_errno($handle)) {
            $this->setError(curl_error($handle));
            curl_close($handle);
            return false;
        }

        // get httd code to identify if request was successful
        $httpcode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
        $this->success = in_array($httpcode, $this->codes);

        curl_close($handle);

        $decoded = json_decode($response, true);

        // request may be successful, but also can have errors, for example, about keys
        if (isset($decoded['error']) && $error = $decoded['error']) {
            if (is_array($error)) {
                $error = $this->assocToString($error);
            }
            $this->setError($error);
        }

        if (! $this->success) {
            return false;
        }

        return $decoded;
    }
945325
public function request(string $method, string $path, array $parameters = [])
    {
        $options = [
            'headers' => [
                'Authorization' => sprintf('Key %s', $this->apiKey),
                'User-Agent' => sprintf(
                  'Clarifai PHP (https://github.com/darrynten/clarifai-php);v%s;%s',
                  \DarrynTen\Clarifai\Clarifai::VERSION,
                  phpversion()
                ),
            ],
        ];

        // TODO check for batch operation
        return $this->handleRequest(
            $method,
            sprintf('%s/%s/%s', $this->url, $this->version, $path),
            $options,
            $parameters
        );
    }
1271332
protected function httpRequest($method, $uri, array $options = [])
    {
        if (null !== $this->proxy) {
            $options[RequestOptions::PROXY] = $this->proxy;
        }

        if (!isset($options[RequestOptions::HEADERS])) {
            $options[RequestOptions::HEADERS] = $this->getHttpHeaders();
        } else {
            $options[RequestOptions::HEADERS] = array_merge($this->getHttpHeaders(), $options[RequestOptions::HEADERS]);
        }

        if (!isset($options[RequestOptions::HTTP_ERRORS])) {
            $options[RequestOptions::HTTP_ERRORS] = false;
        }

        if (!isset($options[RequestOptions::ALLOW_REDIRECTS])) {
            $options[RequestOptions::ALLOW_REDIRECTS] = false;
        }

        if (!isset($options[RequestOptions::TIMEOUT]) && null !== $this->timeout) {
            $options[RequestOptions::TIMEOUT] = $this->timeout;
        }

        if (null !== $this->qps && null !== $this->lastRequestTime) {
            $lastInterval = floor((microtime(true) - $this->lastRequestTime) * 1000000);
            $timeout = ceil(1000000 / $this->qps);
            if ($lastInterval < $timeout) {
                usleep($timeout - $lastInterval);
            }
        }

        $response = $this->getHttpClient()->request($method, $uri, $options);
        $this->lastRequestTime = microtime(true);
        $this->history[] = [
            'method' => $method,
            'uri' => $uri,
            'time' => $this->lastRequestTime,
            'status' => $response->getStatusCode(),
        ];

        return $response;
    }
546577
public function add($method = 'GET', $uri = '/', $pattern = '', array $options = [])
    {
        $this->method[] = $method;

        $this->uri[] = $uri;

        $this->pattern[] = $pattern;

        $this->filter[$uri][$method] = (isset($options['filter'])) ? $options['filter'] : '';
    }
51188
public function pathInfoFilter($path, $options = false)
    {
        if ($options) {
            $output = pathinfo($path, $options);
        } else {
            $output = pathinfo($path);
        }
        return $output;
    }
893732
private function generateCacheKey($method, $uri, array $options = [])
    {
        return sha1(sprintf('%s.%s.%s.%s', get_class($this), $method, $uri, json_encode($options)));
    }
188866
public static function doRequest($method, $url, $options = [])
    {
        $curl = curl_init();
        // GET参数设置
        if (!empty($options['query'])) {
            $url .= (stripos($url, '?') !== false ? '&' : '?') . http_build_query($options['query']);
        }
        // CURL头信息设置
        if (!empty($options['headers'])) {
            curl_setopt($curl, CURLOPT_HTTPHEADER, $options['headers']);
        }
        // POST数据设置
        if (strtolower($method) === 'post') {
            curl_setopt($curl, CURLOPT_POST, true);
            curl_setopt($curl, CURLOPT_POSTFIELDS, self::_buildHttpData($options['data']));
        }
        // 证书文件设置
        if (!empty($options['ssl_cer'])) if (file_exists($options['ssl_cer'])) {
            curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM');
            curl_setopt($curl, CURLOPT_SSLCERT, $options['ssl_cer']);
        } else throw new InvalidArgumentException("Certificate files that do not exist. --- [ssl_cer]");
        // 证书文件设置
        if (!empty($options['ssl_key'])) if (file_exists($options['ssl_key'])) {
            curl_setopt($curl, CURLOPT_SSLKEYTYPE, 'PEM');
            curl_setopt($curl, CURLOPT_SSLKEY, $options['ssl_key']);
        } else throw new InvalidArgumentException("Certificate files that do not exist. --- [ssl_key]");
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_TIMEOUT, 60);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        list($content) = [curl_exec($curl), curl_close($curl)];
        // 清理 CURL 缓存文件
        if (!empty(self::$cache_curl)) foreach (self::$cache_curl as $key => $file) {
            Tools::delCache($file);
            unset(self::$cache_curl[$key]);
        }
        return $content;
    }