Skip to content

Commit

Permalink
#24: Made automatic driver injection conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
Inaki Anduaga committed Jan 28, 2015
1 parent 6199c6f commit d55ea76
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Models/ModelWithExternalStorageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ protected static function boot()
{
parent::boot();

static::injectStorageDriver();
//Attempt to auto-inject the storage driver if we haven't initialized it yet
if(static::$storageDriver === null) {
static::injectStorageDriver();
}

/**
* Creating Event
Expand Down Expand Up @@ -219,12 +222,15 @@ public function syncStorageDriverField()
// ---------------------------

/**
* Inject storage driver and pass configuration
* Inject storage driver and pass configuration using the app IoC container
*/
private static function injectStorageDriver()
{
static::$storageDriver = app(StorageDriver::class);
static::$storageDriver->setConfigKey(static::$storageDriverConfigPath);
//Only attempt to inject driver if there is a IoC binding for the interface
if(App::getBindings()[StorageDriver::class]) {
static::$storageDriver = app(StorageDriver::class);
static::$storageDriver->setConfigKey(static::$storageDriverConfigPath);
}
}

/**
Expand Down

0 comments on commit d55ea76

Please sign in to comment.