Detects if API call should use streaming endpoint, and if yes, which one

@param string $method The API method to call

@return string|false Variant of streaming API to be used
161016
protected function _detectStreaming($method) {
    $streamings = [
      'public' => [
        'statuses/sample',
        'statuses/filter'
      ]
    ];
    foreach ($streamings as $key => $values) {
      if (in_array($method, $values)) {
        return $key;
      }
    }

    return false;
  }
1072393
protected function getApiInstance($method)
    {
        $class = "\\Cartalyst\\Stripe\\Api\\".ucwords($method);

        if (class_exists($class) && ! (new ReflectionClass($class))->isAbstract()) {
            return new $class($this->config);
        }

        throw new \BadMethodCallException("Undefined method [{$method}] called.");
    }
1352942
public function setTransport($method=null){
        switch($method){
            case "stream":
                $this->defaultOptions= array_merge_recursive($this->defaultOptions,[
                    'stream'        => true,
                    'stream_context' => [
                        'ssl' => [
                            'verify_peer' => false,
                            'verify_peer_name' => false,
                            'allow_self_signed' => true
                        ]
                    ]
                ]);
                break;
            case "curl":
            default:
                $method = 'curl';
                break;
        }
        $this->transportMethod = $method;
        return $this->initClient(); 
    }
527025
public function method( $method = false ) : string
	{
		if( true === $method ){
			return (isset( $this->server['request_method'] ) ?? $this->server['request_method']);
		} elseif( !$this->method ){
			if( isset( $_server['http_x_method_override'] ) ){
				$this->method = strtoupper( $this->server['http_x_method_override'] );
			} else{
				$this->method = strtoupper( isset( $this->server['request_method'] ) ? $this->server['request_method'] : null );
			}
		}
		return $this->method;
	}
257516
protected function checkActive($url,$method)
    {
        if(is_array($url)){
            return call_user_func_array(array($this->request,$method), $url) ? $this->activeValue : $this->inActiveValue;
        } else{
            return $this->request->{$method}($url) ? $this->activeValue : $this->inActiveValue;
        }
    }
79064
protected function findClass($method)
	{
		if (!preg_match("/^add([a-zA-Z]+)/", $method, $matches)) {
			return false;
		}

		$className = "\\HtmlForm\\Elements\\{$matches[1]}";

		if (!class_exists($className)) {
			return false;
		}

		return $className;
	}
752974
protected function _detectMethod($method, $params)
    {
        // multi-HTTP method endpoints
        switch($method) {
            case 'account/settings':
                $method = count($params) > 0 ? $method . '__post' : $method;
                break;
        }

        $apimethods = $this->getApiMethods();
        foreach ($apimethods as $httpmethod => $methods) {
            if (in_array($method, $methods)) {
                return $httpmethod;
            }
        }
        throw new \Exception('Can\'t find HTTP method to use for "' . $method . '".');
    }
841701
protected function getEndpoint($method)
    {
        $number = $this->getArgument("number");
        $this->delArgument("number");
        $endpoint = "contacts";
        if (!is_null($number)) {
            $endpoint .= "/$number/variables";
        }
        $name = $this->getArgument("name");
        if (!is_null($name)) {
            $endpoint .= "/$name";
            $this->delArgument("name");
        }
        $queryString = array();
        $withContactLists = $this->getArgument("with_contact_lists");
        if (!is_null($withContactLists)) {
            $queryString['with_contact_lists'] = "true";
            $this->delArgument("with_contact_lists");
        }
        $page = $this->getArgument("page");
        if (!is_null($page)) {
            $queryString['page'] = $page;
            $this->delArgument("page");
        }
        if (!empty($queryString)) {
            $queryString = http_build_query($queryString);
            return "$endpoint?$queryString";
        }
        return $endpoint;
    }
1351535
protected function filterMethod($method): ?string
    {
        if ($method === null) {
            return $method;
        }

        if (!\is_string($method)) {
            throw new \InvalidArgumentException(sprintf(
                'Unsupported HTTP method; must be a string, received %s',
                (\is_object($method) ? \get_class($method) : \gettype($method))
            ));
        }

        $method = \strtoupper($method);
        if (!isset($this->validMethods[$method])) {
            throw new \InvalidArgumentException($this, $method);
        }

        return $method;
    }
488799
public function call(string $method)
    {
        $args = $this->getArgs($method);

        $return = call_user_func_array([$this, $method], $args);

        $out = $this->renderer->render($this->statusCode, $this->headers, $return);

        self::response()->addHeader('Content-Type', $this->renderer->getContentType());
        if ($this->renderer->sendHeader()) {
            foreach ($this->headers as $name => $value) {
                self::response()->addHeader('x-' . ucfirst($name), $value);
            }

            self::response()->setStatus($this->statusCode);
        }

        return $out;
    }
395262
protected function run($method)
    {
        $endpoint = $this->getEndpoint($method);
        $outputFile = $this->getArgument('accept_file');
        if (is_null($outputFile)) {
            $outputFile = $this->getArgument('accept_any_file');
        }
        if (is_null($outputFile)) {
            $outputFile = $this->getArgument('accept_sound_file');
        }
        $cType = $this->getContentType($method);
        $aCType = $this->getAcceptContentType($method);
        $this->delArgument('accept_file');
        $this->delArgument('accept_any_file');
        $this->delArgument('accept_sound_file');
        $body = $this->getBody($method);
        return $this->client->run(
            $endpoint,
            $method,
            $cType,
            $aCType,
            $body,
            $outputFile
        );
    }
89417
public function makeRequest($endpoint, array $parameters = array(), $method = 'GET')
    {
        $response = array();

        // Validate if this endpoint has a BC url
        $bcEndpoint = null;
        if (!$this->bcAttempt) {
            if (!empty($this->bcRegexEndpoints)) {
                foreach ($this->bcRegexEndpoints as $regex => $bc) {
                    if (preg_match('@'.$regex.'@', $endpoint)) {
                        $this->bcAttempt = true;
                        $bcEndpoint = preg_replace('@'.$regex.'@', $bc, $endpoint);

                        break;
                    }
                }
            }
        }

        $url = $this->baseUrl.$endpoint;

        // Don't make the call if we're unit testing a BC endpoint
        if (!$bcEndpoint || !$this->bcTesting || ($bcEndpoint && $this->bcTesting && $this->bcAttempt)) {
            // Hack for unit testing to ensure this isn't being called due to a bad regex
            if ($this->bcTesting && !$this->bcAttempt) {
                $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
                if (!is_array($this->bcTesting)) {
                    $this->bcTesting = array($this->bcTesting);
                }

                // The method is not catching the BC endpoint so fail the test
                if (in_array($bt[1]['function'], $this->bcTesting)) {
                    throw new \Exception($endpoint.' not matched in '.var_export($this->bcRegexEndpoints, true));
                }
            }
            $this->bcAttempt = false;

            if (strpos($url, 'http') === false) {
                $error = array(
                    'code'    => 500,
                    'message' => sprintf(
                        'URL is incomplete.  Please use %s, set the base URL as the third argument to $MauticApi->newApi(), or make $endpoint a complete URL.',
                        __CLASS__.'setBaseUrl()'
                    )
                );
            } else {
                try {
                    $settings = [];
                    if (method_exists($this, 'getTemporaryFilePath')) {
                        $settings['temporaryFilePath'] = $this->getTemporaryFilePath();
                    }
                    $response = $this->auth->makeRequest($url, $parameters, $method, $settings);

                    $this->getLogger()->debug('API Response', array('response' => $response));

                    if (!is_array($response)) {
                        $this->getLogger()->warning($response);

                        //assume an error
                        $error = array(
                            'code'    => 500,
                            'message' => $response
                        );
                    }

                    // @deprecated support for 2.6.0 to be removed in 3.0
                    if (!isset($response['errors']) && isset($response['error']) && isset($response['error_description'])) {
                        $message = $response['error'].': '.$response['error_description'];

                        $this->getLogger()->warning($message);

                        $error = array(
                            'code'    => 403,
                            'message' => $message
                        );
                    }
                } catch (\Exception $e) {
                    $this->getLogger()->error('Failed connecting to Mautic API: '.$e->getMessage(), array('trace' => $e->getTraceAsString()));

                    $error = array(
                        'code'    => $e->getCode(),
                        'message' => $e->getMessage()
                    );
                }
            }

            if (!empty($error)) {
                return array(
                    'errors' => array($error),
                    // @deprecated 2.6.0 to be removed 3.0
                    'error'  => $error
                );
            } elseif (!empty($response['errors'])) {
                $this->getLogger()->error('Mautic API returned errors: '.var_export($response['errors'], true));
            }

            // @deprecated 2.6.0 BC error handling
            // @todo remove in 3.0
            if (isset($response['error']) && !isset($response['errors'])) {
                if (isset($response['error_description'])) {
                    // BC Oauth2 error
                    $response['errors'] = array(
                        array(
                            'message' => $response['error_description'],
                            'type'    => $response['error']
                        )
                    );
                } elseif (isset($response['message'])) {
                    $response['errors'] = array(
                        $response['error']
                    );
                }
            }

            // Ensure a code is present in the error array
            if (!empty($response['errors'])) {
                $info = $this->auth->getResponseInfo();
                foreach ($response['errors'] as $key => $error) {
                    if (!isset($response['errors'][$key]['code'])) {
                        $response['errors'][$key]['code'] = $info['http_code'];
                    }
                }
            }
        }

        // Check for a 404 code and a BC URL then try again if applicable
        if ($bcEndpoint && ($this->bcTesting || (!empty($response['errors'][0]['code']) && (int) $response['errors'][0]['code'] === 404))) {
            $this->bcAttempt = true;

            return $this->makeRequest($bcEndpoint, $parameters, $method);
        }

        return $response;
    }
332031
protected function request(string $method, string $endpoint, $json = null)
    {
        $uri = $this->buildUri($endpoint);
        $options = $json != null ? ['json' => $json] : [];

        try {
            $response = $this->client->request($method, $uri, $options);
        } catch (ClientException $exception) {
            throw $this->determineException($exception);
        }

        $body = (string) $response->getBody();

        return $this->jsonValidator($body) ? json_decode($body, true) : $body;
    }
1102049
protected function getMethodPartAndVerb($method)
    {
        preg_match($this->methodRule, $method, $matches);

        return empty($matches) ? false : array_slice($matches, 1);
    }
76912
private function getFallbackHandler(string $method)
    {
        if (empty($this->fallback)) {
            return null;
        }

        $fallback   = \fallback($this->fallback);
        $interfaces = class_implements(static::class);
        foreach ($interfaces as $interface) {
            if (is_subclass_of($fallback, $interface)) {
                return [$fallback, $method];
            }
        }

        App::warning(sprintf('The %s class does not implement the %s interface', get_parent_class($fallback), JsonHelper::encode($interfaces, JSON_UNESCAPED_UNICODE)));

        return null;
    }
642300
private function getHttpMethodAndResourcesFromMethod(\ReflectionMethod $method, $resource)
    {
        // if method doesn't match regex - skip
        if (!preg_match('/([a-z][_a-z0-9]+)(.*)Action/', $method->getName(), $matches)) {
            return false;
        }

        $httpMethod = strtolower($matches[1]);
        $resources = preg_split(
            '/([A-Z][^A-Z]*)/', $matches[2], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE
        );
        $isCollection = false;
        $isInflectable = true;

        if (0 === strpos($httpMethod, self::COLLECTION_ROUTE_PREFIX)
            && in_array(substr($httpMethod, 1), $this->availableHTTPMethods)
        ) {
            $isCollection = true;
            $httpMethod = substr($httpMethod, 1);
        } elseif ('options' === $httpMethod) {
            $isCollection = true;
        }

        if ($isCollection && !empty($resource)) {
            $resourcePluralized = $this->generateResourceName(end($resource));
            $isInflectable = ($resourcePluralized != $resource[count($resource) - 1]);
            $resource[count($resource) - 1] = $resourcePluralized;
        }

        $resources = array_merge($resource, $resources);

        return [$httpMethod, $resources, $isCollection, $isInflectable];
    }
747324
private function getUrl($method)
    {
        return sprintf(
            $this::API_URL,
            $this->getDc(),
            $this->getApiVersion(),
            $method
        );
    }