1: <?php
2:
3: class Sesha_Factory_Driver extends Horde_Core_Factory_Base
4: {
5: private $_instances = array();
6:
7: public function create($name = '', $params = array())
8: {
9: if (!isset($this->_instances[$name])) {
10: if (!empty($params['driver'])) {
11: $driver = $params['driver'];
12: unset($params['driver']);
13: } else {
14: $driver = $GLOBALS['conf']['storage']['driver'];
15: $params = Horde::getDriverConfig('storage', $driver);
16: }
17: $class = 'Sesha_Driver_' . ucfirst(basename($driver));
18:
19: if (!class_exists($class)) {
20: throw new Sesha_Exception(sprintf('Unable to load the definition of %s.', $class));
21: }
22:
23: switch ($class) {
24: case 'Sesha_Driver_Sql':
25: if (empty($params['db'])) {
26: $params['db'] = $this->_injector->getInstance('Horde_Core_Factory_Db')->create('sesha', $params);
27: }
28: break;
29: }
30: $this->_instances[$name] = new $class($params);
31: }
32:
33: return $this->_instances[$name];
34: }
35:
36: }
37: