1: <?php
2: /**
3: * A Horde_Injector based Horde_Auth_Imap:: factory.
4: *
5: * PHP version 5
6: *
7: * @author Michael Slusarz <slusarz@horde.org>
8: * @category Horde
9: * @license http://www.horde.org/licenses/gpl GPL
10: * @link http://pear.horde.org/index.php?package=IMP
11: * @package IMP
12: */
13:
14: /**
15: * A Horde_Injector based Horde_Auth_Imap:: factory.
16: *
17: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (GPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/gpl.
21: *
22: * @author Michael Slusarz <slusarz@horde.org>
23: * @category Horde
24: * @license http://www.horde.org/licenses/gpl GPL
25: * @link http://pear.horde.org/index.php?package=IMP
26: * @package IMP
27: */
28: class IMP_Factory_AuthImap extends Horde_Core_Factory_Injector
29: {
30: /**
31: * Return the Horde_Auth_Imap:: instance that uses IMP configuration.
32: *
33: * @return Horde_Auth_Imap The singleton instance.
34: * @throws IMP_Exception
35: */
36: public function create(Horde_Injector $injector)
37: {
38: $params = $GLOBALS['registry']->callByPackage('imp', 'server');
39: if (is_null($params)) {
40: throw new IMP_Exception('No server parameters found.');
41: }
42:
43: $aparams = $GLOBALS['session']->get('imp', 'imap_admin', Horde_Session::TYPE_ARRAY);
44:
45: $params = array_merge(
46: $params,
47: (isset($aparams['params']) ? $aparams['params'] : array()),
48: array(
49: 'default_user' => $GLOBALS['registry']->getAuth(),
50: 'logger' => $injector->getInstance('Horde_Log_Logger')
51: )
52: );
53:
54: if (isset($params['admin_password'])) {
55: $secret = $injector->getInstance('Horde_Secret');
56: $params['admin_password'] = $secret->read($secret->getKey('imp'), $params['admin_password']);
57: }
58:
59: return Horde_Auth::factory('Imap', $params);
60: }
61:
62: }
63: