Webiny\Component\TwitterOAuth\TwitterOAuthLoader::getInstance PHP Method

getInstance() public static method

Returns an instance to TwitterOAuth server based on the current configuration.
public static getInstance ( string $key ) : array | TwitterOAuth
$key string Unique identifier for the TwitterOAuth server that you wish to get.
return array | TwitterOAuth
    public static function getInstance($key)
    {
        if (isset(self::$instances[$key])) {
            return self::$instances;
        }
        $config = TwitterOAuth::getConfig()->get($key, false);
        if (!$config) {
            throw new TwitterOAuthException('Unable to read "TwitterOAuth.' . $key . '" configuration.');
        }
        if (strpos($config->RedirectUri, 'http://') !== false || strpos($config->RedirectUri, 'https://') !== false) {
            $redirectUri = $config->RedirectUri;
        } else {
            $redirectUri = self::httpRequest()->getCurrentUrl(true)->setPath($config->RedirectUri)->setQuery('')->val();
        }
        $instance = \Webiny\Component\TwitterOAuth\Bridge\TwitterOAuth::getInstance($config->ClientId, $config->ClientSecret, $redirectUri);
        return new TwitterOAuth($instance);
    }

Usage Example

示例#1
0
 /**
  * Base constructor.
  *
  * @param string $serverName  Name of the TwitterOAuth server in the current configuration.
  * @param string|array $roles Roles that will be set for the OAuth users.
  *
  * @throws TwitterOAuthException
  */
 public function __construct($serverName, $roles)
 {
     try {
         $this->connection = TwitterOAuthLoader::getInstance($serverName);
         $this->oauthRoles = (array) $roles;
     } catch (\Exception $e) {
         throw new TwitterOAuthException($e->getMessage());
     }
 }
All Usage Examples Of Webiny\Component\TwitterOAuth\TwitterOAuthLoader::getInstance
TwitterOAuthLoader