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 IMP_Compose factory.
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_Compose
24: extends Horde_Core_Factory_Base
25: implements Horde_Shutdown_Task
26: {
27: /** Storage key for compose objects. */
28: const STORAGE_KEY = 'compose_ob/';
29:
30: /**
31: * Instances.
32: *
33: * @var array
34: */
35: private $_instances = array();
36:
37: /**
38: */
39: public function __construct(Horde_Injector $injector)
40: {
41: parent::__construct($injector);
42:
43: Horde_Shutdown::add($this);
44: }
45:
46: /**
47: * Return the IMP_Compose:: instance.
48: *
49: * @param string $cacheid The cache ID string.
50: *
51: * @return IMP_Compose The singleton compose instance.
52: * @throws IMP_Exception
53: */
54: public function create($cacheid = null)
55: {
56: global $session;
57:
58: if (empty($cacheid)) {
59: $cacheid = strval(new Horde_Support_Randomid());
60: } elseif (!isset($this->_instances[$cacheid])) {
61: $this->_instances[$cacheid] = $session->get('imp', self::STORAGE_KEY . $cacheid);
62: }
63:
64: if (empty($this->_instances[$cacheid])) {
65: $this->_instances[$cacheid] = new IMP_Compose($cacheid);
66: }
67:
68: return $this->_instances[$cacheid];
69: }
70:
71: /**
72: * Tasks to perform on shutdown.
73: */
74: public function shutdown()
75: {
76: global $session;
77:
78: foreach ($this->_instances as $key => $val) {
79: switch ($val->changed) {
80: case 'changed':
81: $session->set('imp', self::STORAGE_KEY . $key, $val);
82: break;
83:
84: case 'deleted':
85: $session->remove('imp', self::STORAGE_KEY . $key);
86: break;
87: }
88: }
89: }
90:
91: /**
92: * Return a list of all compose objects currently stored in the session.
93: *
94: * @return array List of IMP_Compose objects.
95: */
96: public function getAllObs()
97: {
98: global $session;
99:
100: return $session->get('imp', self::STORAGE_KEY, $session::TYPE_ARRAY);
101: }
102:
103: }
104: