1: <?php
2: /**
3: * The factory for the tasklists handler.
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @author Gunnar Wrobel <wrobel@pardus.de>
9: * @package Nag
10: */
11: class Nag_Factory_Tasklists
12: {
13: /**
14: * Tasklists drivers already created.
15: *
16: * @var array
17: */
18: private $_instances = array();
19:
20: /**
21: * The injector.
22: *
23: * @var Horde_Injector
24: */
25: private $_injector;
26:
27: /**
28: * Constructor.
29: *
30: * @param Horde_Injector $injector The injector to use.
31: */
32: public function __construct(Horde_Injector $injector)
33: {
34: $this->_injector = $injector;
35: }
36:
37: /**
38: * Return a Nag_Tasklists instance.
39: *
40: * @return Nag_Tasklists
41: */
42: public function create()
43: {
44: if (!isset($GLOBALS['conf']['tasklists']['driver'])) {
45: $driver = 'Default';
46: } else {
47: $driver = Horde_String::ucfirst($GLOBALS['conf']['tasklists']['driver']);
48: }
49: if (empty($this->_instances[$driver])) {
50: $class = 'Nag_Tasklists_' . $driver;
51: if (class_exists($class)) {
52: $params = array();
53: if (!empty($GLOBALS['conf']['share']['auto_create'])) {
54: $params['auto_create'] = true;
55: }
56: switch ($driver) {
57: case 'Default':
58: $params['identity'] = $this->_injector->getInstance('Horde_Core_Factory_Identity')->create();
59: break;
60: }
61: $this->_instances[$driver] = new $class(
62: $GLOBALS['nag_shares'],
63: $GLOBALS['registry']->getAuth(),
64: $params
65: );
66: } else {
67: throw new Nag_Exception(sprintf('Unable to load the definition of %s.', $class));
68: }
69: }
70: return $this->_instances[$driver];
71: }
72: }