1: <?php
2: /**
3: * A Horde_Injector based factory for the IMP_Quota object.
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 factory for the IMP_Quota object.
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_Quota extends Horde_Core_Factory_Injector
29: {
30: /**
31: * Return the IMP_Quota instance.
32: *
33: * @return IMP_Quota The singleton instance.
34: * @throws IMP_Exception
35: */
36: public function create(Horde_Injector $injector)
37: {
38: $qparams = $GLOBALS['session']->get('imp', 'imap_quota');
39:
40: if (!isset($qparams['driver'])) {
41: throw new IMP_Exception('Quota config missing driver parameter.');
42: }
43: $driver = $qparams['driver'];
44: $params = isset($qparams['params'])
45: ? $qparams['params']
46: : array();
47:
48: /* If 'password' exists in params, it has been encrypted in the
49: * session so we need to decrypt. */
50: if (isset($params['password'])) {
51: $secret = $injector->getInstance('Horde_Secret');
52: $params['password'] = $secret->read($secret->getKey('imp'), $params['password']);
53: }
54:
55: $imap_ob = $injector->getInstance('IMP_Factory_Imap')->create();
56:
57: switch (Horde_String::lower($driver)) {
58: case 'imap':
59: $params['imap_ob'] = $imap_ob;
60: $params['mbox'] = IMP::$mailbox->search
61: ? 'INBOX'
62: : IMP::$mailbox;
63: break;
64:
65: case 'sql':
66: $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('imp', $params);
67: break;
68: }
69:
70: $params['username'] = $imap_ob->getParam('username');
71:
72: return IMP_Quota::factory($driver, $params);
73: }
74:
75: }
76: