1: <?php
2: /**
3: * A Horde_Injector based factory for the IMP_Flags 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_Flags 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_Flags extends Horde_Core_Factory_Injector
29: {
30: /**
31: * Return the IMP_Flags instance.
32: *
33: * @return IMP_Flags The singleton instance.
34: */
35: public function create(Horde_Injector $injector)
36: {
37: try {
38: $instance = $GLOBALS['session']->get('imp', 'flags');
39: } catch (Exception $e) {
40: Horde::logMessage('Could not unserialize stored IMP_Flags object.', 'DEBUG');
41: $instance = null;
42: }
43:
44: if (is_null($instance)) {
45: $instance = new IMP_Flags();
46: }
47:
48: register_shutdown_function(array($this, 'shutdown'), $instance);
49:
50: return $instance;
51: }
52:
53: /**
54: * Store serialized version of object in the current session.
55: *
56: * @param IMP_Flags $instance Flags object.
57: */
58: public function shutdown($instance)
59: {
60: /* Only need to store the object if the object has changed. */
61: if ($instance->changed) {
62: $GLOBALS['session']->set('imp', 'flags', $instance);
63: }
64: }
65:
66: }
67: