{
public function create(Horde_Injector $injector)
{
- $driver = empty($GLOBALS['conf']['cache']['driver'])
- ? 'Null'
- : $GLOBALS['conf']['cache']['driver'];
- if (strcasecmp($driver, 'None') === 0) {
- $driver = 'Null';
- }
-
- $params = Horde::getDriverConfig('cache', $driver);
- if (isset($GLOBALS['conf']['cache']['default_lifetime'])) {
- $params['lifetime'] = $GLOBALS['conf']['cache']['default_lifetime'];
- }
-
- $logger = $injector->getInstance('Horde_Log_Logger');
- $params['logger'] = $logger;
-
- $base_params = $params;
-
- if (strcasecmp($driver, 'Memcache') === 0) {
- $params['memcache'] = $injector->getInstance('Horde_Memcache');
- } elseif (strcasecmp($driver, 'Sql') === 0) {
- $params['db'] = $injector->getInstance('Horde_Db')->getDb('horde', 'cache');
- }
-
- if (!empty($GLOBALS['conf']['cache']['use_memorycache']) &&
- ((strcasecmp($driver, 'Sql') === 0) ||
- (strcasecmp($driver, 'File') === 0))) {
- if (strcasecmp($GLOBALS['conf']['cache']['use_memorycache'], 'Memcache') === 0) {
- $base_params['memcache'] = $injector->getInstance('Horde_Memcache');
- }
-
- $params = array(
- 'stack' => array(
- array(
- 'driver' => $GLOBALS['conf']['cache']['use_memorycache'],
- 'params' => $base_params
- ),
- array(
- 'driver' => $driver,
- 'params' => $params
- )
- )
- );
- $driver = 'Stack';
- }
-
- return Horde_Cache::factory($driver, $params);
+ $cache = new Horde_Core_Factory_Cache($injector);
+ return $cache->getCache();
}
public function equals(Horde_Injector_Binder $binder)
--- /dev/null
+<?php
+/**
+ * @category Horde
+ * @package Core
+ */
+class Horde_Core_Binder_CacheFactory implements Horde_Injector_Binder
+{
+ public function create(Horde_Injector $injector)
+ {
+ return new Horde_Core_Factory_Cache($injector);
+ }
+
+ public function equals(Horde_Injector_Binder $binder)
+ {
+ return false;
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * A Horde_Injector:: based Horde_Cache:: factory.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Core
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Core
+ */
+
+/**
+ * A Horde_Injector:: based Horde_Cache:: factory.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Core
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Core
+ */
+class Horde_Core_Factory_Cache
+{
+ /**
+ * The injector.
+ *
+ * @var Horde_Injector
+ */
+ private $_injector;
+
+ /**
+ * Singleton instances.
+ *
+ * @var array
+ */
+ private $_instances = array();
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Injector $injector The injector to use.
+ */
+ public function __construct(Horde_Injector $injector)
+ {
+ $this->_injector = $injector;
+ }
+
+ /**
+ * Return the Horde_Cache:: instance.
+ *
+ * @param array $opts Options:
+ * <pre>
+ * 'session' - (boolean) Fallback to session driver, instead of null
+ * driver, if no cache config is found.
+ * DEFAULT: false
+ * </pre>
+ *
+ * @return Horde_Cache_Base The singleton instance.
+ * @throws Horde_Cache_Exception
+ */
+ public function getCache(array $opts = array())
+ {
+ $driver = empty($GLOBALS['conf']['cache']['driver'])
+ ? 'Null'
+ : $GLOBALS['conf']['cache']['driver'];
+ if (strcasecmp($driver, 'None') === 0) {
+ $driver = 'Null';
+ }
+
+ if (($driver == 'Null') && !empty($opts['session'])) {
+ $driver = 'Session';
+ }
+
+ if (!isset($this->_instances[$driver])) {
+ $params = Horde::getDriverConfig('cache', $driver);
+ if (isset($GLOBALS['conf']['cache']['default_lifetime'])) {
+ $params['lifetime'] = $GLOBALS['conf']['cache']['default_lifetime'];
+ }
+
+ $logger = $this->_injector->getInstance('Horde_Log_Logger');
+ $params['logger'] = $logger;
+
+ $base_params = $params;
+
+ if (strcasecmp($driver, 'Memcache') === 0) {
+ $params['memcache'] = $this->_injector->getInstance('Horde_Memcache');
+ } elseif (strcasecmp($driver, 'Sql') === 0) {
+ $params['db'] = $this->_injector->getInstance('Horde_Db')->getDb('horde', 'cache');
+ }
+
+ if (!empty($GLOBALS['conf']['cache']['use_memorycache']) &&
+ ((strcasecmp($driver, 'Sql') === 0) ||
+ (strcasecmp($driver, 'File') === 0))) {
+ if (strcasecmp($GLOBALS['conf']['cache']['use_memorycache'], 'Memcache') === 0) {
+ $base_params['memcache'] = $this->_injector->getInstance('Horde_Memcache');
+ }
+
+ $params = array(
+ 'stack' => array(
+ array(
+ 'driver' => $GLOBALS['conf']['cache']['use_memorycache'],
+ 'params' => $base_params
+ ),
+ array(
+ 'driver' => $driver,
+ 'params' => $params
+ )
+ )
+ );
+ $driver = 'Stack';
+ }
+
+ $this->_instances[$driver] = Horde_Cache::factory($driver, $params);
+ }
+
+ return $this->_instances[$driver];
+ }
+
+}
'Horde_Auth' => 'Horde_Core_Binder_Auth',
// 'Horde_Browser' - initialized below
'Horde_Cache' => 'Horde_Core_Binder_Cache',
+ 'Horde_Cache_Factory' => 'Horde_Core_Binder_CacheFactory',
'Horde_Core_Auth_Signup' => 'Horde_Core_Binder_AuthSignup',
'Horde_Crypt' => 'Horde_Core_Binder_Crypt',
'Horde_Data' => 'Horde_Core_Binder_Data',
<file name="Auth.php" role="php" />
<file name="AuthSignup.php" role="php" />
<file name="Cache.php" role="php" />
+ <file name="CacheFactory.php" role="php" />
<file name="Crypt.php" role="php" />
<file name="Data.php" role="php" />
<file name="Db.php" role="php" />
<dir name="Factory">
<file name="Ajax.php" role="php" />
<file name="Auth.php" role="php" />
+ <file name="Cache.php" role="php" />
<file name="Crypt.php" role="php" />
<file name="Data.php" role="php" />
<file name="Db.php" role="php" />
<install as="Horde/Core/Binder/Auth.php" name="lib/Horde/Core/Binder/Auth.php" />
<install as="Horde/Core/Binder/AuthSignup.php" name="lib/Horde/Core/Binder/AuthSignup.php" />
<install as="Horde/Core/Binder/Cache.php" name="lib/Horde/Core/Binder/Cache.php" />
+ <install as="Horde/Core/Binder/CacheFactory.php" name="lib/Horde/Core/Binder/CacheFactory.php" />
<install as="Horde/Core/Binder/Crypt.php" name="lib/Horde/Core/Binder/Crypt.php" />
<install as="Horde/Core/Binder/Data.php" name="lib/Horde/Core/Binder/Data.php" />
<install as="Horde/Core/Binder/Db.php" name="lib/Horde/Core/Binder/Db.php" />
<install as="Horde/Core/Controller/SettingsFinder.php" name="lib/Horde/Core/Controller/SettingsFinder.php" />
<install as="Horde/Core/Factory/Ajax.php" name="lib/Horde/Core/Factory/Ajax.php" />
<install as="Horde/Core/Factory/Auth.php" name="lib/Horde/Core/Factory/Auth.php" />
+ <install as="Horde/Core/Factory/Cache.php" name="lib/Horde/Core/Factory/Cache.php" />
<install as="Horde/Core/Factory/Crypt.php" name="lib/Horde/Core/Factory/Crypt.php" />
<install as="Horde/Core/Factory/Data.php" name="lib/Horde/Core/Factory/Data.php" />
<install as="Horde/Core/Factory/Db.php" name="lib/Horde/Core/Factory/Db.php" />