1: <?php
2:
3: class Kronolith_Factory_Storage extends Horde_Core_Factory_Base
4: {
5: 6: 7: 8: 9:
10: private $_instances = array();
11:
12: 13: 14: 15: 16: 17:
18: public function create($params = array())
19: {
20: if (empty($params['user'])) {
21: $user = $GLOBALS['registry']->getAuth();
22: } else {
23: $user = $params['user'];
24: unset($params['user']);
25: }
26:
27: if (empty($params['driver'])) {
28: $driver = Horde_String::ucfirst($GLOBALS['conf']['storage']['driver']);
29: } else {
30: $driver = $params['driver'];
31: unset($params['driver']);
32: }
33: $driver = basename($driver);
34: $class = 'Kronolith_Storage_' . $driver;
35:
36: $driver_params = Horde::getDriverConfig('storage', 'Sql');
37: if ($driver == 'Sql') {
38: if ($driver_params != 'Horde') {
39:
40: $params['db'] = $this->_injector->getInstance('Horde_Core_Factory_Db')->create('kronolith', Horde::getDriverConfig('storage', 'Sql'));
41: } else {
42:
43: $params['db'] = $this->_injector->getInstance('Horde_Db_Adapter');
44: }
45: $params['table'] = $driver_params['table'];
46: }
47:
48: if (class_exists($class)) {
49: $driver = new $class($user, $params);
50: } else {
51: throw new Kronolith_Exception(sprintf(_("Unable to load the definition of %s."), $class));
52: }
53:
54: try {
55: $driver->initialize();
56: } catch (Exception $e) {
57: $driver = new Kronolith_Storage($params);
58: }
59:
60: return $driver;
61: }
62:
63: }
64: