1: <?php
2: /**
3: * The factory for the notepads handler.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Mnemo
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/apache
11: * @link http://www.horde.org/apps/mnemo
12: */
13:
14: /**
15: * The factory for the notepads handler.
16: *
17: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file LICENSE for license information (ASL). If you
20: * did not receive this file, see http://www.horde.org/licenses/apache.
21: *
22: * @category Horde
23: * @package Mnemo
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/apache
26: * @link http://www.horde.org/apps/mnemo
27: */
28: class Mnemo_Factory_Notepads
29: {
30: /**
31: * Notepads drivers already created.
32: *
33: * @var array
34: */
35: private $_instances = array();
36:
37: /**
38: * The injector.
39: *
40: * @var Horde_Injector
41: */
42: private $_injector;
43:
44: /**
45: * Constructor.
46: *
47: * @param Horde_Injector $injector The injector to use.
48: */
49: public function __construct(Horde_Injector $injector)
50: {
51: $this->_injector = $injector;
52: }
53:
54: /**
55: * Return a Mnemo_Notepads instance.
56: *
57: * @return Mnemo_Notepads
58: */
59: public function create()
60: {
61: if (!isset($GLOBALS['conf']['notepads']['driver'])) {
62: $driver = 'Default';
63: } else {
64: $driver = Horde_String::ucfirst($GLOBALS['conf']['notepads']['driver']);
65: }
66: if (empty($this->_instances[$driver])) {
67: $class = 'Mnemo_Notepads_' . $driver;
68: if (class_exists($class)) {
69: $params = array();
70: if (!empty($GLOBALS['conf']['share']['auto_create'])) {
71: $params['auto_create'] = true;
72: }
73: switch ($driver) {
74: case 'Default':
75: $params['identity'] = $this->_injector->getInstance('Horde_Core_Factory_Identity')->create();
76: break;
77: }
78: $this->_instances[$driver] = new $class(
79: $GLOBALS['mnemo_shares'],
80: $GLOBALS['registry']->getAuth(),
81: $params
82: );
83: } else {
84: throw new Mnemo_Exception(sprintf('Unable to load the definition of %s.', $class));
85: }
86: }
87: return $this->_instances[$driver];
88: }
89: }