1: <?php
2: /**
3: * Horde_Injector factory to create Mnemo_Driver instances.
4: *
5: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file LICENSE for license information (ASL). If you
8: * did not receive this file, see http://www.horde.org/licenses/apache.
9: *
10: * @author Michael J. Rubinsky <mrubinsk@horde.org>
11: * @package Mnemo
12: */
13: class Mnemo_Factory_Driver
14: {
15: /**
16: * Instances.
17: *
18: * @var array
19: */
20: private $_instances = array();
21:
22: /**
23: * The injector.
24: *
25: * @var Horde_Injector
26: */
27: private $_injector;
28:
29: /**
30: * Constructor.
31: *
32: * @param Horde_Injector $injector The injector to use.
33: */
34: public function __construct(Horde_Injector $injector)
35: {
36: $this->_injector = $injector;
37: }
38:
39: /**
40: * Return the Mnemo_Driver:: instance.
41: *
42: * @param mixed $name The notepad to open
43: *
44: * @return Mnemo_Driver
45: * @throws Mnemo_Exception
46: */
47: public function create($name = '')
48: {
49: if (!isset($this->_instances[$name])) {
50: $driver = $GLOBALS['conf']['storage']['driver'];
51: $params = Horde::getDriverConfig('storage', $driver);
52: $class = 'Mnemo_Driver_' . ucfirst(basename($driver));
53: if (!class_exists($class)) {
54: throw new Mnemo_Exception(sprintf('Unable to load the definition of %s.', $class));
55: }
56:
57: switch ($class) {
58: case 'Mnemo_Driver_Sql':
59: $params = array(
60: 'db' => $this->_injector->getInstance('Horde_Db_Adapter'),
61: 'table' => 'mnemo_memos',
62: 'charset' => $params['charset'],
63: );
64: break;
65:
66: case 'Mnemo_Driver_Kolab':
67: $params = array(
68: 'storage' => $this->_injector->getInstance('Horde_Kolab_Storage')
69: );
70: }
71: $driver = new $class($name, $params);
72: $this->_instances[$name] = $driver;
73: }
74:
75: return $this->_instances[$name];
76: }
77: }
78: