Support the ongoing development of Laravel.io →
posted 10 years ago
IOC

Hi Ive got a class that is has a service provider ( Ive renamed the Class to hidden in this sample.)

$this->app['hidden'] = $this->app->share(function($app){
            $version = $app['config']->get('hidden/client::version');
            $manifestPath = $app['config']->get('hidden/client::manifest_path');
            $baseUrl = $app['config']->get('hidden/client::base_url');

          return new Hidden($version,$manifestPath,$baseUrl);
    });

Now this is a Guzzle client so the version and Guzzle service descriptors are loaded now the web service dose not use OAuth 2 so what Im doing in a Route::get closure I call the login method and than save the token to the instance but the next time I ask the container for the class I get a class with none of the properties set

  Route::get('hauth', function() use ($app) {
        $response = $app['hidden']->api()->login(['username' => 'jason', 'password' => 'password']);
          $app['hidden']->setToken($response['token']);

  });

   Route::get('someroute',function() use ($app) {
           $app['hidden']->getToken();
          //this is null the token is no longer set.

  });

now the next time I ask for $app['hidden'] the token property is not set now Ive tried to use share or singleton but none seem to work

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

apps4u apps4u Joined 7 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.