Support the ongoing development of Laravel.io →
posted 10 years ago
IOC
Last updated 2 years ago.
0

Ok, problem solved, this was just me not understanding. I didn't want to bind to a type like "app.myservice" because the purpose of the bindings is for dependency injection. This worked exactly how the documentation describes deferred providers, just put the full type in the array returned from provides(), so for the above example, my whole service provider looks like:

  /**
   * Whether or not to defer the loading of this service
   * provider until it's needed
   *
   * @var boolean
   */
  protected $defer = true;

  /**
   * Register bindings with the IoC container
   *
   * @return void
   */
  public function register() {

    $this->app->bind('League\Flysystem\Filesystem', function($app) {

      $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
        'username' => $app['config']->get('services.rackspace.username'),
        'apiKey' => $app['config']->get('services.rackspace.key'),
      ));

      $store = $client->objectStoreService('cloudFiles', 'SYD');
      $container = $store->getContainer($app['config']->get('services.rackspace.container'));

      return new Filesystem(new Adapter($container));

    });

  }

  /**
   * The services that this service provider registers
   *
   * @return array
   */
  public function provides() {
    return ['League\Flysystem\Filesystem'];
  }
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

maknz maknz Joined 13 Mar 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.

© 2024 Laravel.io - All rights reserved.