1: <?php
2: /**
3: * Copyright 2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * A Horde_Injector based IMP_Mailbox_SessionCache factory.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Factory_MailboxCache
24: extends Horde_Core_Factory_Injector
25: implements Horde_Shutdown_Task
26: {
27: /** Storage key. */
28: const STORAGE_KEY = 'mbox_cache';
29:
30: /**
31: * Instance.
32: *
33: * @var IMP_Mailbox_SessionCache
34: */
35: private $_instance;
36:
37: /**
38: * Return the IMP_Mailbox_SessionCache instance.
39: *
40: * @return IMP_Mailbox_SessionCache Cache instance.
41: */
42: public function create(Horde_Injector $injector)
43: {
44: global $session;
45:
46: if (!($this->_instance = $session->get('imp', self::STORAGE_KEY))) {
47: $this->_instance = new IMP_Mailbox_SessionCache();
48: }
49:
50: Horde_Shutdown::add($this);
51:
52: return $this->_instance;
53: }
54:
55: /**
56: * Saves IMP_Mailbox cache data to the session.
57: */
58: public function shutdown()
59: {
60: global $session;
61:
62: if ($this->_instance->changed == IMP_Mailbox_SessionCache::CHANGED_YES) {
63: $session->set('imp', self::STORAGE_KEY, $this->_instance);
64: }
65: }
66:
67: }
68: