Ever since setting the Cache was moved out of the constructor, accessing it was broke...
authorChuck Hagenbuch <chuck@horde.org>
Mon, 31 May 2010 02:01:45 +0000 (22:01 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Mon, 31 May 2010 02:01:45 +0000 (22:01 -0400)
We need to delegate back up to the Adapter now, which also means adding getter
methods for the Cache and Logger.

framework/Db/lib/Horde/Db/Adapter/Base.php
framework/Db/lib/Horde/Db/Adapter/Base/Schema.php

index 3b6f81a..8939e02 100644 (file)
@@ -118,9 +118,8 @@ abstract class Horde_Db_Adapter_Base implements Horde_Db_Adapter
         /* Can't set cache/logger in constructor - these objects may use DB
          * for storage. Add stubs for now - they have to be manually set
          * later with setCache() and setLogger(). */
-        $stub = new Horde_Support_Stub();
-        $this->_cache = $stub;
-        $this->_logger = $stub;
+        $this->_cache = new Horde_Support_Stub();
+        $this->_logger = new Horde_Support_Stub();
 
         // Default to UTF-8
         if (!isset($config['charset'])) {
@@ -163,7 +162,7 @@ abstract class Horde_Db_Adapter_Base implements Horde_Db_Adapter
 
 
     /*##########################################################################
-    # Dependency setters
+    # Dependency setters/getters
     ##########################################################################*/
 
     /**
@@ -179,6 +178,14 @@ abstract class Horde_Db_Adapter_Base implements Horde_Db_Adapter
     }
 
     /**
+     * @return Horde_Cache_Base
+     */
+    public function getCache()
+    {
+        return $this->_cache;
+    }
+
+    /**
      * Set a logger object.
      *
      * @inject
@@ -190,6 +197,14 @@ abstract class Horde_Db_Adapter_Base implements Horde_Db_Adapter
         $this->_logger = $logger;
     }
 
+    /**
+     * return Horde_Log_Logger
+     */
+    public function getLogger()
+    {
+        return $this->_logger;
+    }
+
 
     /*##########################################################################
     # Object composition
index e85c96b..911014b 100644 (file)
 abstract class Horde_Db_Adapter_Base_Schema
 {
     /**
-     * @var Cache object
-     */
-    protected $_cache = null;
-
-    /**
-     * @var Logger
-     */
-    protected $_logger = null;
-
-    /**
      * @var Horde_Db_Adapter_Base
      */
     protected $_adapter = null;
@@ -56,9 +46,6 @@ abstract class Horde_Db_Adapter_Base_Schema
     {
         $this->_adapter = $adapter;
         $this->_adapterMethods = array_flip(get_class_methods($adapter));
-
-        $this->_cache = isset($config['cache']) ? $config['cache'] : new Horde_Support_Stub;
-        $this->_logger = isset($config['logger']) ? $config['logger'] : new Horde_Support_Stub;
     }
 
 
@@ -118,6 +105,8 @@ abstract class Horde_Db_Adapter_Base_Schema
      *
      * @param  string  $method
      * @param  array   $args
+     *
+     * @return mixed
      */
     public function __call($method, $args)
     {
@@ -128,6 +117,21 @@ abstract class Horde_Db_Adapter_Base_Schema
         throw new BadMethodCallException('Call to undeclared method "'.$method.'"');
     }
 
+    /**
+     * Delegate access to $_cache and $_logger to the adapter object.
+     *
+     * @param  string  $key
+     *
+     * @return mixed
+     */
+    public function __get($key)
+    {
+        if ($key == '_cache' || $key == '_logger') {
+            $getter = 'get' . ucfirst(substr($key, 1));
+            return $this->_adapter->$getter();
+        }
+    }
+
 
     /*##########################################################################
     # Quoting