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_Search 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_Search extends Horde_Core_Factory_Injector implements Horde_Shutdown_Task
24: {
25: /**
26: * @var IMP_Search
27: */
28: private $_instance;
29:
30: /**
31: * Return the IMP_Search instance.
32: *
33: * @return IMP_Search The singleton instance.
34: */
35: public function create(Horde_Injector $injector)
36: {
37: try {
38: $this->_instance = $GLOBALS['session']->get('imp', 'search');
39: } catch (Exception $e) {
40: Horde::log('Could not unserialize stored IMP_Search object.', 'DEBUG');
41: }
42:
43: if (!$this->_instance) {
44: $this->_instance = new IMP_Search();
45: }
46:
47: Horde_Shutdown::add($this);
48:
49: return $this->_instance;
50: }
51:
52: /**
53: * Store serialized version of object in the current session.
54: */
55: public function shutdown()
56: {
57: /* Only need to store the object if the object has changed. */
58: if ($this->_instance->changed) {
59: $GLOBALS['session']->set('imp', 'search', $this->_instance);
60: }
61: }
62:
63: }
64: