1: <?php
2: 3: 4:
5: class Whups_Factory_Driver extends Horde_Core_Factory_Base
6: {
7: 8: 9: 10: 11:
12: private $_instances = array();
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: public function create($driver = null, $params = array())
24: {
25: if (is_null($driver)) {
26: $driver = $GLOBALS['conf']['tickets']['driver'];
27: }
28: if (!empty($this->_instances[$driver])) {
29: return $this->_instances[$driver];
30: }
31: $driver = basename($driver);
32: $class = 'Whups_Driver_' . $driver;
33: if (class_exists($class)) {
34: if (is_null($params)) {
35: $params = Horde::getDriverConfig('tickets', $driver);
36: }
37: $this->_instances[$driver] = new $class($params);
38: switch ($driver) {
39: case 'Sql':
40: $this->_instances[$driver]
41: ->setStorage($GLOBALS['injector']->getInstance('Horde_Core_Factory_Db')->create('whups', 'tickets'));
42: }
43:
44: return $this->_instances[$driver];
45: } else {
46: throw new Whups_Exception(sprintf('No such backend "%s" found', $driver));
47: }
48: }
49:
50: }
51: