1: <?php
2: /**
3: * Copyright 2010-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 2010-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * A Horde_Injector based factory for the IMP_Ftree object.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2010-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Factory_Ftree
24: extends Horde_Core_Factory_Injector
25: implements Horde_Shutdown_Task
26: {
27: /* Storage key in session. */
28: const STORAGE_KEY = 'ftree';
29:
30: /**
31: * @var IMP_Ftree
32: */
33: private $_instance;
34:
35: /**
36: * Return the IMP_Ftree object.
37: *
38: * @return IMP_Ftree The singleton instance.
39: */
40: public function create(Horde_Injector $injector)
41: {
42: global $registry, $session;
43:
44: $this->_instance = $session->get('imp', self::STORAGE_KEY);
45:
46: if (!($this->_instance instanceof IMP_Ftree)) {
47: $this->_instance = new IMP_Ftree();
48: }
49:
50: switch ($registry->getView()) {
51: case $registry::VIEW_DYNAMIC:
52: case $registry::VIEW_SMARTMOBILE:
53: $this->_instance->eltdiff->track = true;
54: break;
55: }
56:
57: Horde_Shutdown::add($this);
58:
59: return $this->_instance;
60: }
61:
62: /**
63: * Store serialized version of object in the current session.
64: */
65: public function shutdown()
66: {
67: global $session;
68:
69: /* Only need to store the object if the tree has changed. */
70: if ($this->_instance->changed) {
71: $session->set('imp', self::STORAGE_KEY, $this->_instance);
72: }
73: }
74:
75: }
76: