public static function getInstance($baseUrl = null, $key = null, $secret = null)
 {
     if (!self::$instance && func_num_args() != 3) {
         throw new LogicException('You must specify consumer key and consumer secret to get a consumer.');
     }
     if (func_num_args() == 3) {
         self::$instance = new OpenPNEOAuth($baseUrl, $key, $secret);
     }
     return self::$instance;
 }
 public function authenticate()
 {
     $result = parent::authenticate();
     // Callback from Twitter
     $callbackToken = $this->getRequest()->getParameter('oauth_token');
     $callbackVerifier = $this->getRequest()->getParameter('oauth_verifier');
     if ($callbackToken && $callbackVerifier) {
         // Get user access tokens out of the session.
         $accessToken = sfContext::getInstance()->getUser()->getAttribute('accessToken');
         if (0 == strcmp($callbackToken, $accessToken['oauth_token'])) {
             $instance = OpenPNEOAuth::getInstance($this->urlApiRoot, $this->consumerKey, $this->consumerSecret);
             $newToken = $instance->getAccessToken($callbackToken, $callbackVerifier);
             $twitterUserId = $newToken['user_id'];
             $twitterScreenName = $newToken['screen_name'];
             $twitterAccessToken = $newToken['oauth_token'];
             $twitterTokenSecret = $newToken['oauth_token_secret'];
             $line = Doctrine::getTable('MemberConfig')->findOneByNameAndValue("twitter_user_id", $twitterUserId);
             if ($line) {
                 // 登録済み
                 $member_id = (int) $line->member_id;
                 $member = Doctrine::getTable('Member')->find($member_id);
             } else {
                 // 新規登録
                 $member = Doctrine::getTable('Member')->createPre();
                 $member->setConfig('twitter_user_id', $twitterUserId);
             }
             $member->setConfig('twitter_screen_name', $twitterScreenName);
             $member->setConfig('twitter_oauth_token', $twitterAccessToken);
             $member->setConfig('twitter_oauth_token_secret', $twitterTokenSecret);
             $member->setName($twitterScreenName);
             $member->setIsActive(true);
             $member->save();
             $result = $member->getId();
         }
         return $result;
     }
     //コールバックでは無く、最初にログインボタン押されたらこちら
     $instance = OpenPNEOAuth::getInstance($this->urlApiRoot, $this->consumerKey, $this->consumerSecret);
     $requestToken = $instance->getRequestToken($this->urlCallback);
     // Set user access tokens out of the session.
     sfContext::getInstance()->getUser()->setAttribute('accessToken', $requestToken);
     header('Location: ' . $this->urlAuthorize . $requestToken['oauth_token']);
     exit;
 }