1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Sam_Factory_Driver extends Horde_Core_Factory_Injector
16: {
17: 18: 19:
20: private $_instances = array();
21:
22: 23: 24: 25: 26: 27:
28: public function create(Horde_Injector $injector)
29: {
30: $backend = Sam::getPreferredBackend();
31: $signature = hash('md5', serialize($backend));
32:
33: if (empty($this->_instances[$signature])) {
34: $user = Sam::mapUser($backend['hordeauth']);
35:
36: switch ($backend['driver']) {
37: case 'Amavisd_Sql':
38: case 'Spamd_Sql':
39: try {
40: $db = $injector->getInstance('Horde_Core_Factory_Db')
41: ->create('sam', array_merge(Horde::getDriverConfig(null, 'sql'), $backend['params']));
42: } catch (Horde_Exception $e) {
43: throw new Sam_Exception($e);
44: }
45: $params = array_merge($backend['params'], array('db' => $db));
46: break;
47:
48: case 'Spamd_Ldap':
49: $params = array_merge(
50: array('binddn' => sprintf('%s=%s,%s',
51: $backend['params']['uid'],
52: $user,
53: $backend['params']['basedn']),
54: 'bindpw' => $GLOBALS['registry']->getAuthCredential('password')),
55: $backend['params']);
56: try {
57: $ldap = $injector->getInstance('Horde_Core_Factory_Ldap')
58: ->create('sam', $params);
59: } catch (Horde_Exception $e) {
60: throw new Sam_Exception($e);
61: }
62: $params = array_merge($backend['params'], array('ldap' => $ldap));
63: break;
64:
65: case 'Spamd_Ftp':
66: $params = array_merge(
67: array('username' => $user,
68: 'password' => $GLOBALS['registry']->getAuthCredential('password')),
69: $backend['params']);
70: try {
71: $vfs = $injector->getInstance('Horde_Core_Factory_Vfs')
72: ->create('sam',
73: array('type' => 'ftp',
74: 'params' => $params));
75: } catch (Horde_Exception $e) {
76: throw new Sam_Exception($e);
77: }
78: $params = array_merge($backend['params'], array('vfs' => $vfs));
79: break;
80: }
81:
82: $class = 'Sam_Driver_' . $backend['driver'];
83: $this->_instances[$signature] = new $class($user, $params);
84: }
85:
86: return $this->_instances[$signature];
87: }
88: }
89: