MOON
Server: Apache
System: Linux server1.studioinfinity.com.br 2.6.32-954.3.5.lve1.4.90.el6.x86_64 #1 SMP Tue Feb 21 12:26:30 UTC 2023 x86_64
User: artinside (517)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/artinside/www/lhh/themes/en/assets/include/rs-plugin/php/twitter/connection/Application.php
<?php
namespace TwitterPhp\Connection;

use TwitterPhp\RestApiException;

class Application extends Base
{
    /**
     * @var string
     */
    private $_consumerKey;

    /**
     * @var string
     */
    private $_consumerSecret;

    /**
     * @var string
     */
    private $_bearersToken = null;

    /**
     * @param string $consumerKey
     * @param string $consumerSecret
     */
    public function __construct($consumerKey,$consumerSecret)
    {
        $this->_consumerKey = $consumerKey;
        $this->_consumerSecret = $consumerSecret;
    }

    /**
     * @param string $url
     * @param array $parameters
     * @param $method
     * @return array
     */
    protected function _buildHeaders($url,array $parameters = null,$method)
    {
        return $headers = array(
                    "Authorization: Bearer " . $this->_getBearerToken()
                );
    }

    /**
     * Get Bearer token
     *
     * @link https://dev.twitter.com/docs/auth/application-only-auth
     *
     * @throws \TwitterPhp\RestApiException
     * @return string
     */
    private function _getBearerToken() {
        if (!$this->_bearersToken) {
            $token = urlencode($this->_consumerKey) . ':' . urlencode($this->_consumerSecret);
            $token = base64_encode($token);

            $headers = array(
                "Authorization: Basic " . $token
            );

            $options = array (
                CURLOPT_URL => self::TWITTER_API_AUTH_URL,
                CURLOPT_HTTPHEADER => $headers,
                CURLOPT_POST => 1,
                CURLOPT_POSTFIELDS => "grant_type=client_credentials"
            );

            $response = $this->_callApi($options);

            if (isset($response["token_type"]) && $response["token_type"] == 'bearer') {
                $this->_bearersToken = $response["access_token"];
            } else {
                throw new RestApiException('Error while getting access token');
            }
        }
        return $this->_bearersToken;
    }
}