1: <?php
2: /**
3: * A logger 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: * A logger 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_Logged
29: extends Horde_Kolab_Session_Decorator_Base
30: {
31: /**
32: * The logger.
33: *
34: * @var mixed
35: */
36: private $_logger;
37:
38: /**
39: * Constructor.
40: *
41: * The provided logger class needs to implement the methods info() and
42: * err().
43: *
44: * @param Horde_Kolab_Session $session The session handler.
45: * @param mixed $logger The logger instance.
46: */
47: public function __construct(Horde_Kolab_Session $session, $logger)
48: {
49: parent::__construct($session);
50: $this->_logger = $logger;
51: }
52:
53: /**
54: * Try to connect the session handler.
55: *
56: * @param string $user_id The user ID to connect with.
57: * @param array $credentials An array of login credentials. For Kolab,
58: * this must contain a "password" entry.
59: *
60: * @return NULL
61: *
62: * @throws Horde_Kolab_Session_Exception If the connection failed.
63: */
64: public function connect($user_id = null, array $credentials = null)
65: {
66: try {
67: $this->_session->connect($user_id, $credentials);
68: $this->_logger->info(
69: sprintf(
70: "Connected Kolab session for \"%s\".",
71: $this->_session->getId()
72: )
73: );
74: } catch (Horde_Kolab_Session_Exception $e) {
75: $this->_logger->err(
76: sprintf(
77: "Failed to connect Kolab session for \"%s\". Error was: %s",
78: $this->_session->getMail(), $e->getMessage()
79: )
80: );
81: throw $e;
82: }
83: }
84:
85: /**
86: * Export the session data as array.
87: *
88: * @return array The session data.
89: */
90: public function export()
91: {
92: $session_data = $this->_session->export();
93: $this->_logger->info(
94: sprintf(
95: "Exported session data for \"%s\" (%s).",
96: $this->_session->getMail(), serialize($session_data)
97: )
98: );
99: return $session_data;
100: }
101:
102: /**
103: * Import the session data from an array.
104: *
105: * @param array The session data.
106: *
107: * @return NULL
108: */
109: public function import(array $session_data)
110: {
111: $this->_session->import($session_data);
112: $this->_logger->info(
113: sprintf(
114: "Imported session data for \"%s\" (%s).",
115: $this->_session->getMail(), serialize($session_data)
116: )
117: );
118: }
119:
120: /**
121: * Clear the session data.
122: *
123: * @return NULL
124: */
125: public function purge()
126: {
127: $this->_logger->warn(
128: sprintf(
129: "Purging session data for \"%s\".",
130: $this->_session->getMail()
131: )
132: );
133: $this->_session->purge();
134: }
135: }
136: