/** * OauthStack constructor. * @param array|null $credentials * @throws TwitterStreamingException */ public function __construct(array $credentials = null) { parent::__construct(); try { // Check if Dotenv library is loaded // If credentials are provided, let's prioritize those // values instead of take in consideration the Dotenv library if (class_exists('Dotenv\\Dotenv') && !$credentials) { /** * Load the .env files which must contain * the token of your Twitter Application */ if (file_exists(getcwd() . DIRECTORY_SEPARATOR . '.env')) { (new Dotenv(getcwd()))->load(); } else { (new Dotenv(dirname(getcwd())))->load(); } } else { // If Dotenv library are not loaded, the credentials should // be provided in the constructor of the Tracker if (!is_array($credentials) || !count($credentials)) { throw new TwitterStreamingException(sprintf('TwitterStreaming suggests to use vlucas/phpdotenv ' . 'library to store you Twitter app credentials. ' . 'If you do not want to use it, you should provide those ' . 'values in the Tracker instance. Please take a look the example: ' . '"examples/WithoutDotEnv.php"')); } $this->credentials = $credentials; } } catch (TwitterStreamingException $e) { exit($e->getMessage()); } }
public function __construct() { // Necesary to retrieve the stack (or create the new instance if doesnt exists) parent::__construct(); }
public function connect($method, $url, array $parameters = []) { $this->method = $method; $this->url = $url; $this->parameters = $parameters; $this->flag = $this->method == 'POST' ? 'form_params' : 'query'; try { /** * Load the stack from BaseStrack class */ $stack = BaseStack::getStack(); /** * All the request must have these values, so let's assign * them here and save memory :) */ $this->client = new Client(['base_uri' => $this->url['api'], 'handler' => $stack, 'auth' => 'oauth']); } catch (Exception $e) { throw new TwitterStreamingException($e->getMessage()); } return $this; }