dhruvil12 / oauth-php

Automatically exported from code.google.com/p/oauth-php
MIT License
0 stars 0 forks source link

OAuthStore with different options #93

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi everyone,

if you call the method below like that : 
OAuthStore::instance("2Leg", $options1);

and then call (in the same script) :
OAuthStore::instance("2Leg", $options2);

with $options1 and $options2 that are different.
The instance of the singleton will not be updated and the second call
will use options of the first call and the signature of your OAuth second call 
will by consequence fail.

To correct that use, I change the code of the OAuthStore.php file like that 
(take a look at the $forceNewInstance parameter) :
class OAuthStore
{
    static private $instance = false;

    /**
     * Request an instance of the OAuthStore
     */
    public static function instance ( $store = 'MySQL', $options = array(), $forceNewInstance = false )
    {
        if (!OAuthStore::$instance || $forceNewInstance)
        {
            // Select the store you want to use
            if (strpos($store, '/') === false)
            {
                $class = 'OAuthStore'.$store;
                $file  = dirname(__FILE__) . '/store/'.$class.'.php';
            }
            else
            {
                $file  = $store;
                $store = basename($file, '.php');
                $class = $store;
            }

            if (is_file($file))
            {
                require_once $file;

                if (class_exists($class))
                {
                    OAuthStore::$instance = new $class($options);
                }
                else
                {
                    throw new OAuthException2('Could not find class '.$class.' in file '.$file);
                }
            }
            else
            {
                throw new OAuthException2('No OAuthStore for '.$store.' (file '.$file.')');
            }
        }
        return OAuthStore::$instance;   
    }
}

Original issue reported on code.google.com by florian....@gmail.com on 11 Jan 2011 at 3:03

GoogleCodeExporter commented 9 years ago
I'm not sure why you'd need to change stores, but you probably have a reason to 
do so. So your patch is accepted and in r182. Thanks!

Original comment by brunobg%...@gtempaccount.com on 12 Jan 2011 at 2:57