@param callable $api
@param array $params
@param mixed $default

@return array|string|null
487698
private function callGitHub(callable $api, array $params = [], $default = null)
    {
        try {
            $response = $api(...$params);

        } catch (RequestException $e) {
            $response = $default;

        } catch (RuntimeException $e) {
            $response = $default;
        }

        return $response;
    }
95064
protected function callScope(callable $scope, $parameters = [])
    {
        array_unshift($parameters, $this);

        $query = $this->getQuery();

        // We will keep track of how many wheres are on the query before running the
        // scope so that we can properly group the added scope constraints in the
        // query as their own isolated nested where statement and avoid issues.
        $originalWhereCount = count($query->wheres);

        $result = $scope(...array_values($parameters)) ?: $this;

        if (count($query->wheres) > $originalWhereCount) {
            $this->addNewWheresWithinGroup($query, $originalWhereCount);
        }

        return $result;
    }
1114251
public function getPossibleCalls(ReflectionParameter ...$params) : array
    {
        if (!count($params)) {
            return [[]];
        }
        $options = [];
        $opts = [];
        $annotations = new Annotations($this);
        foreach ($params as $i => $param) {
            if (!$param->hasType()) {
                if (isset($annotations['param'][$i])) {
                    if (is_string($annotations['param']) && $i === 0) {
                        $opts[] = $this->extractTypeFromAnnotation($annotations['param']);
                    } else {
                        $opts[] = $this->extractTypeFromAnnotation($annotations['param'][$i]);
                    }
                } else {
                    $opts[] = 'mixed';
                }
            } else {
                $opts[] = $param->getType()->__toString();
            }
        }
        $options[] = $opts;
        $last = array_pop($params);
        if ($last->isOptional() && !$last->isVariadic()) {
            $options = array_merge($options, $this->getPossibleCalls(...$params));
        }
        return $options;
    }
313724
protected function prepare(&$params, $api) {
        $params ['api']     = $api;
        $params ['app_key'] = $this->appKey;
        if (!isset($params['v'])) {
            $params ['v'] = $this->ver;
        }
        if (!isset($params['sign_method'])) {
            $params['sign_method'] = 'hmac';
        }
        if (!isset($params['timestamp'])) {
            $params['timestamp'] = gmdate('Y-m-d H:i:s') . ' GMT';
        }
        if (!isset($params['format'])) {
            $params['format'] = 'json';
        }
        $params ['sign'] = $this->signer->sign($params, $this->appSecret);
        if (!$this->curl) {
            $this->curl = curl_init();
        }
        curl_setopt($this->curl, CURLOPT_AUTOREFERER, 1);
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->curl, CURLOPT_TIMEOUT, $this->timeout);
        curl_setopt($this->curl, CURLOPT_POSTFIELDS, []);
        if ($this->cookies) {
            curl_setopt($this->curl, CURLOPT_COOKIE, implode('; ', $this->cookies));
        }
        if ($this->headers) {
            curl_setopt($this->curl, CURLOPT_HTTPHEADER, array_values($this->headers));
        }
    }
1197314
public static function getAndRemove(
        array &$params,
        string $key,
        $default = null
    ) {
        $value = self::get(
            $params,
            $key,
            $default
        );

        self::remove(
            $params,
            $key
        );

        return $value;
    }
1064943
public static function getBool(
        array $params,
        string $key,
        $default = null
    ) {
        if (self::has($params, $key)) {
            return (bool)$params[$key];
        }

        return $default;
    }
1015977
public function call($method, array $params = array())
    {
        $params = array($this->getSession(), $method, $params);
        return $this->getClient()->call('call', $params);
    }
921389
public function get($key, $default = null, $params = [])
    {
        $params = array_merge($this->_defaults, $params);

        foreach ($params['objects'] as $object) {
            if ($object && ($object instanceof ViewableData) && $object->$key) {
                return $object->$key;
            }
        }

        // Grab mapping from object
        $mapping = (array)Config::inst()->get('environment', 'mapping');
        $objects = array_reverse($params['objects'], true);

        foreach ($objects as $object) {
            if ($object && method_exists($object, 'config')) {
                $mapping = array_merge($mapping, (array)$object->config()->db_to_environment_mapping);
            }
        }

        $mapping = array_merge($mapping, $params['mapping']);

        if (isset($mapping[$key])) {
            $key = $mapping[$key];
        }

        // 1. Check cache for valid key and return if found
        if ($params['fromCache'] && array_key_exists($key, $this->_cache)) {
            return $this->_cache[$key] === null ? $default : $this->_cache[$key];
        }

        $value = $default;

        // The function to check the $_ENV vars
        $findInEnvironment = function ($key) use ($params) {
            $value = null;

            if (isset($_ENV[$key])) {
                $value = $_ENV[$key];
            }

            if (getenv($key)) {
                $value = getenv($key);
            }

            if (is_callable($params['parseEnvVarFn'])) {
                $value = call_user_func_array($params['parseEnvVarFn'], [$value, $key]);
            }

            return $value;
        };

        // If key has dots, check recursively
        if (strpos($key, '.')) {
            $keyParts = explode('.', $key);

            // First part of key can denote multiple classes separated by a pipe (or)
            $namespaces = explode('|', array_shift($keyParts));

            // 2. Check \Config class for original value
            foreach ($namespaces as $namespace) {
                // Do a callback to get a value from a function sent in (this is for checking SiteConfig)
                if (isset($params['beforeConfigNamespaceCheckCallbacks'][$namespace]) && is_callable($params['beforeConfigNamespaceCheckCallbacks'][$namespace])) {
                    $value = call_user_func_array($params['beforeConfigNamespaceCheckCallbacks'][$namespace],
                        [$keyParts, $key]);

                    if ($value !== null) {
                        break;
                    }
                }

                $config = Config::inst()->forClass($namespace);

                $value = $config->get(implode('.', $keyParts), $params['on']);

                // 3. If value not found explicitly, recursively get if array
                if (!$value && count($keyParts) > 1) {
                    $configKey = array_shift($keyParts);
                    $configValue = $config->get($configKey, $params['on']);

                    if (is_array($configValue)) {
                        $value = array_get($configValue, implode('.', $keyParts));
                    } else {
                        $value = $configValue;
                    }
                }

                if ($value !== null) {
                    break;
                }
            }

            // 4. Check environment for key explicitly
            if ($value === null) {
                $value = $findInEnvironment($key);
            }

            // 5. Otherwise check for key by namespace in environment
            if ($value === null && count($namespaces) > 1) {
                foreach ($namespaces as $namespace) {
                    $value = $findInEnvironment($namespace . '.' . implode('.', $keyParts));

                    if ($value !== null) {
                        break;
                    }
                }
            }

            // 6. Otherwise check for key recursively in environment
            if ($value === null && !empty($keyParts)) {
                foreach ($namespaces as $namespace) {
                    if (($first = $findInEnvironment($namespace)) && is_array($first)) {
                        $value = array_get($first, implode('.', $keyParts));

                        if ($value !== null) {
                            break;
                        }
                    }
                }

                // 7. Otherwise, check for key as is (without namespaces, a global override to assume)
                if ($value === null) {
                    $value = $findInEnvironment(implode('.', $keyParts));
                }
            }
        } else {
            // Or else check in $_ENV vars
            $value = $findInEnvironment($key);
        }

        if ($params['doCache']) {
            $this->_cache[$key] = $value;
        }

        return $value === null ? $default : $value;
    }
456902
public static function create(callable $function, ...$params)
    {
        $tid = self::tid();
        $top = $tid == self::id();
        static::go($function, $params, $tid, $top);
    }
67722
public function getOrApply(string $name, $default = null, ...$param)
    {
        if (! $this->has($name)) {
            call_user_func_array([$this, 'set'], func_get_args());
        }

        if (isset($this->called[$name]['called'])) {
            $this->called[$name] = [
                'value' => call_user_func_array([$this->hook, 'apply'], $this->called[$name]['value'])
            ];
        }

        return $this->called[$name]['value'];
    }
396307
protected static function reach($param, $default = null)
    {
        $p = self::separate($param);
        //
        if ($p['first'] == 'database') {
            return self::callDatabase($p['second']);
        }

        return array_get(self::$params, $param, $default);
    }
920689
protected function _stringifyNullBoolParams($apiparams)
  {
    foreach ($apiparams as $key => $value) {
      if (! is_scalar($value)) {
        // no need to try replacing arrays
        continue;
      }
      if (is_null($value)) {
        $apiparams[$key] = 'null';
      } elseif (is_bool($value)) {
        $apiparams[$key] = $value ? 'true' : 'false';
      }
    }

    return $apiparams;
  }
792742
public function api($method, $params = array())
    {
        if (!in_array($method, $this->supportedUnitpayMethods)) {
            throw new UnexpectedValueException('Method is not supported');
        }

        if (isset($this->requiredUnitpayMethodsParams[$method])) {
            foreach ($this->requiredUnitpayMethodsParams[$method] as $rParam) {
                if (!isset($params[$rParam])) {
                    throw new InvalidArgumentException('Param '.$rParam.' is null');
                }
            }
        }

        $params['secretKey'] = $this->secretKey;
        if (empty($params['secretKey'])) {
            throw new InvalidArgumentException('SecretKey is null');
        }

        $requestUrl = self::API_URL . '?' . http_build_query([
            'method' => $method,
            'params' => $params
        ], null, '&', PHP_QUERY_RFC3986);

        $response = json_decode(file_get_contents($requestUrl));
        if (!is_object($response)) {
            throw new InvalidArgumentException('Temporary server error. Please try again later.');
        }

        return $response;
    }
592680
private static function getResponse(string $uri, array $params = []): array
    {
        self::initialize();

        if (empty($params)) {
            $response = self::$client->get('api/' . self::$version . '/' . $uri);
        } else {
            $response = self::$client->post('api/' . self::$version . '/' . $uri, [
                'form_params' => $params,
            ]);
        }

        return json_decode($response->getBody(), TRUE);
    }
894137
private function fetch($method, $url, $call, array $params = array())
    {
        // Make the API call via the consumer
        $response = $this->OAuth->fetch($method, $url, $call, $params);
        
        // Format the response and return
        switch ($this->responseFormat) {
            case 'json':
                return json_encode($response);
            case 'jsonp':
                $response = json_encode($response);
                return $this->callback . '(' . $response . ')';
            default:
                return $response;
        }
    }
988833
private function _action($params)
    {
        // Shift and get the method
        $method = array_shift($params);

        // Behavior
        if ($this->behaviors[$method]) {
            $this->behaviors[$method]();
        }

        if (!isset($this->routes[$method])) {
            $this->_defaultAction();
        }

        // Get corresponding method name
        $method = $this->routes[$method];

        if (!method_exists($this, $method)) {
            $this->_defaultAction();
        }

        return call_user_func_array([$this, $method], $params);
    }
727786
private function getUrlToOldApi($method, array $params, $format)
    {
        $queryString = sprintf(
            '?apikey=%s&format=%s&method=%s%s',
            $this->getApiKey(),
            $format,
            $method,
            $this->paramsQueryStringBuilder($params)
        );

        return sprintf(
            $this::API_URL,
            $this->getDc(),
            $this->getApiVersion(),
            $queryString
        );
    }