From d55ea76cf1ba077682859d70f272d66435ba7adb Mon Sep 17 00:00:00 2001 From: Inaki Anduaga Date: Wed, 28 Jan 2015 18:27:16 +0100 Subject: [PATCH] #24: Made automatic driver injection conditional --- src/Models/ModelWithExternalStorageTrait.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Models/ModelWithExternalStorageTrait.php b/src/Models/ModelWithExternalStorageTrait.php index e0c1838..335bfa5 100644 --- a/src/Models/ModelWithExternalStorageTrait.php +++ b/src/Models/ModelWithExternalStorageTrait.php @@ -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 @@ -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); + } } /**