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