0

I have been using drawmyattention for integrating my laravel code with xero, we get data from clients database and add it into our CRM. Recently, we got 2nd client who also wanted to integrate with Xero system, the problem i am facing is to change client (organization) i need to change following in config file

Consumer key consumer secret and RSA encryption

But when i change these values in config/xero/config.php file dynamically, since the drawmyattention vendors providers have already been loaded they do not get new values, instead they stick with old values in config file.

I used

config('xero.config.oauth', new array(values))

I can log and see values have changed but when i make connection call it gets data from client 1 and with further logging i came to know that new config values are not progating to providers that have been loaded before.

I tried to create my own defered service provider following

https://laravel.com/docs/5.2/providers

with no luck.

Kind of stuck whereas everything else is working fine just can't switch xero organizations at runtime due to this reason.

The answer in link also talks about same issue but still does could not solve Laravel dynamic config settings

When i create my own

class XeroDefferedProvider extends ServiceProvider
{

    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = true;

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
         $this->app->bind('DrawMyAttention\XeroLaravel\Facades\XeroPrivate', function()
         {
            return new XeroPrivate();

        });
    }


    public function provides()
    {
        return ['DrawMyAttention\XeroLaravel\Facades\XeroPrivate'];
    }
}

I get error that XeroPrivate class does not exists..

and I am also confused between using 'DrawMyAttention\XeroLaravel\Facades\XeroPrivate' or 'DrawMyAttention\XeroLaravel\Providers\XeroServiceProvider'

as later itself is a provider and i think since i need to declare object i need to use facades but ahh i am no pro in laravel.

AbdulMueed
  • 1,327
  • 12
  • 19

1 Answers1

0

for anyone trying to look out the solution, there were two problems, here are solutions for both of them

first i had written provider wrongly, if you are using third party library which also has provider you need to do following

class XeroDefferedProvider extends ServiceProvider
{

    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = true;

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->register(
            'DrawMyAttention\XeroLaravel\Providers\XeroServiceProvider'
        );

        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
        $loader->alias('XeroPrivate', 'DrawMyAttention\XeroLaravel\Facades\XeroPrivate');
    }


    public function provides()
    {
        return ['DrawMyAttention\XeroLaravel\Facades\XeroPrivate'];
    }
}

Secondly to change the values i actually modified variables inside the class object of Xero private.. using reflectionclass functionality, which actually removes the need for writing provider in my case but i am writing both things so that if anyone needs any of the solution they can use it.

            $config = $reflectionClass->getProperty('config');
            $config->setAccessible(true);
            $config->setValue( $objects , $this->_config_defaults);
AbdulMueed
  • 1,327
  • 12
  • 19