1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Wicked_Factory_Driver extends Horde_Core_Factory_Injector
16: {
17: 18: 19:
20: private $_instances = array();
21:
22: 23: 24: 25: 26: 27: 28: 29:
30: public function create(Horde_Injector $injector)
31: {
32: $driver = Horde_String::ucfirst($GLOBALS['conf']['storage']['driver']);
33: if (empty($driver)) {
34: throw new Wicked_Exception('Wicked is not configured');
35: }
36: $signature = serialize(array($driver, $GLOBALS['conf']['storage']['params']['driverconfig']));
37: if (empty($this->_instances[$signature])) {
38: switch ($driver) {
39: case 'Sql':
40: $params = array('db' => $this->getDb($injector));
41: break;
42: }
43: $class = 'Wicked_Driver_' . $driver;
44: $this->_instances[$signature] = new $class($params);
45: }
46:
47: return $this->_instances[$signature];
48: }
49:
50: 51: 52: 53: 54: 55: 56: 57: 58:
59: public function getDb(Horde_Injector $injector)
60: {
61: try {
62: if ($GLOBALS['conf']['storage']['params']['driverconfig'] == 'horde') {
63: return $injector->getInstance('Horde_Db_Adapter');
64: }
65: return $injector->getInstance('Horde_Core_Factory_Db')
66: ->create('wicked', 'storage');
67: } catch (Horde_Exception $e) {
68: throw new Wicked_Exception($e);
69: }
70: }
71: }
72: