From 212ee9909eb2137c17774c94e342d3002b790dac Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Mon, 22 Oct 2012 11:39:42 -0400
Subject: [PATCH] Smarter initializer.

---
 module/VuFind/src/VuFind/Connection/Manager.php        | 10 ++++++----
 .../VuFind/src/VuFind/ServiceManager/Initializer.php   |  5 ++++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/module/VuFind/src/VuFind/Connection/Manager.php b/module/VuFind/src/VuFind/Connection/Manager.php
index 9f2493ee4fa..f6db71da771 100644
--- a/module/VuFind/src/VuFind/Connection/Manager.php
+++ b/module/VuFind/src/VuFind/Connection/Manager.php
@@ -95,10 +95,12 @@ class Manager
         // Set the service locator:
         $index->setServiceLocator(self::$serviceLocator);
 
-        // Set the logger:
-        \VuFind\ServiceManager\Initializer::initInstance(
-            $index, self::$serviceLocator
-        );
+        // Inject dependencies with the standard initializer:
+        if (null !== self::$serviceLocator) {
+            \VuFind\ServiceManager\Initializer::initInstance(
+                $index, self::$serviceLocator
+            );
+        }
 
         return $index;
     }
diff --git a/module/VuFind/src/VuFind/ServiceManager/Initializer.php b/module/VuFind/src/VuFind/ServiceManager/Initializer.php
index cb2cbdbb3a4..d16d26fc0e5 100644
--- a/module/VuFind/src/VuFind/ServiceManager/Initializer.php
+++ b/module/VuFind/src/VuFind/ServiceManager/Initializer.php
@@ -68,7 +68,10 @@ class Initializer
      */
     public static function initPlugin($instance, AbstractPluginManager $manager)
     {
-        static::initInstance($instance, $manager->getServiceLocator());
+        $sm = $manager->getServiceLocator();
+        if (null !== $sm) {
+            static::initInstance($instance, $sm);
+        }
         if (method_exists($instance, 'setPluginManager')) {
             $instance->setPluginManager($manager);
         }
-- 
GitLab