1: <?php
2: /**
3: * Storage for Horde_Kolab_Session handlers.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Session
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Kolab_Session
12: */
13:
14: /**
15: * Storage for Horde_Kolab_Session handlers.
16: *
17: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Kolab
23: * @package Kolab_Session
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Kolab_Session
27: */
28: class Horde_Kolab_Session_Decorator_Stored
29: extends Horde_Kolab_Session_Decorator_Base
30: {
31: /**
32: * The storage.
33: *
34: * @var Horde_Kolab_Session_Storage
35: */
36: private $_storage;
37:
38: /**
39: * Has the session information changed?
40: *
41: * @var boolean
42: */
43: private $_modified = false;
44:
45: /**
46: * Constructor.
47: *
48: * @param Horde_Kolab_Session $session The session handler.
49: * @param Horde_Kolab_Session_Storage $storage Store the session here.
50: */
51: public function __construct(
52: Horde_Kolab_Session $session,
53: Horde_Kolab_Session_Storage $storage
54: )
55: {
56: parent::__construct($session);
57: $this->_storage = $storage;
58: $this->_session->import($this->_storage->load());
59: register_shutdown_function(array($this, 'shutdown'));
60: }
61:
62: /**
63: * Try to connect the session handler.
64: *
65: * @param string $user_id The user ID to connect with.
66: * @param array $credentials An array of login credentials. For Kolab,
67: * this must contain a "password" entry.
68: *
69: * @return NULL
70: *
71: * @throws Horde_Kolab_Session_Exception If the connection failed.
72: */
73: public function connect($user_id = null, array $credentials = null)
74: {
75: $this->_session->connect($user_id, $credentials);
76: $this->_modified = $this->_session->export();
77: }
78:
79: /**
80: * Import the session data from an array.
81: *
82: * @param array The session data.
83: *
84: * @return NULL
85: */
86: public function import(array $session_data)
87: {
88: throw new Horde_Kolab_Session_Exception('Data import of stored session data is handled via the session.');
89: }
90:
91: /**
92: * Clear the session data.
93: *
94: * @return NULL
95: */
96: public function purge()
97: {
98: $this->_session->purge();
99: $this->_modified = array();
100: }
101:
102: /**
103: * Write any modified data to the session.
104: *
105: * @return NULL
106: */
107: public function shutdown()
108: {
109: if ($this->_modified !== false) {
110: $this->_storage->save($this->_modified);
111: }
112: }
113: }
114: