1: <?php
2: /**
3: * Copyright 2013-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 2013-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Temporary data storage implementation for attachment data storage.
16: *
17: * Stores data using Horde_VFS to ensure that data is persistent for the
18: * session. Compose data will be garbage collected at the end of a session
19: * (if a user logs out properly).
20: *
21: * @author Michael Slusarz <slusarz@horde.org>
22: * @category Horde
23: * @copyright 2013-2014 Horde LLC
24: * @license http://www.horde.org/licenses/gpl GPL
25: * @package IMP
26: */
27: class IMP_Compose_Attachment_Storage_Temp
28: extends IMP_Compose_Attachment_Storage
29: {
30: /**
31: * The VFS HashTable object.
32: *
33: * @var Horde_HashTable_Vfs
34: */
35: protected $_ht;
36:
37: /**
38: */
39: public function __construct($user, $id = null)
40: {
41: parent::__construct($user, $id);
42:
43: $this->_ht = new Horde_Core_HashTable_PersistentSession();
44: }
45:
46: /**
47: */
48: protected function _read()
49: {
50: try {
51: return $this->_ht->getStream($this->_id);
52: } catch (Exception $e) {
53: throw new IMP_Compose_Exception($e);
54: }
55: }
56:
57: /**
58: */
59: protected function _write($filename, Horde_Mime_Part $part)
60: {
61: if (!$this->_ht->set($this->_id, $filename, array('filename' => true))) {
62: throw new IMP_Compose_Exception('Could not save attachment data.');
63: }
64: }
65:
66: /**
67: */
68: public function delete()
69: {
70: $this->_ht->delete($this->_id);
71: }
72:
73: /**
74: */
75: public function exists()
76: {
77: return $this->_ht->exists($this->_id);
78: }
79:
80: }
81: