1: <?php
2: /**
3: * A log decorator definition for the Kolab storage drivers.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Storage
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_Storage
12: */
13:
14: /**
15: * A log decorator definition for the Kolab storage drivers.
16: *
17: * Copyright 2010-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_Storage
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_Storage
27: */
28: class Horde_Kolab_Storage_Driver_Decorator_Log
29: extends Horde_Kolab_Storage_Driver_Decorator_Base
30: {
31: /**
32: * A log handler.
33: *
34: * @var mixed
35: */
36: private $_logger;
37:
38: /**
39: * Constructor.
40: *
41: * @param Horde_Kolab_Storage_Driver $driver The decorated driver.
42: * @param mixed $logger The log handler. This instance
43: * must provide the info() method.
44: */
45: public function __construct(Horde_Kolab_Storage_Driver $driver, $logger)
46: {
47: $this->_logger = $logger;
48: parent::__construct($driver);
49: }
50:
51: /**
52: * Create the backend driver.
53: *
54: * @return mixed The backend driver.
55: */
56: public function createBackend()
57: {
58: $this->_logger->info(
59: sprintf('Driver "%s": Creating backend.', $this->getDriverName())
60: );
61: $result = $this->_driver->createBackend();
62: $this->_logger->info(
63: sprintf(
64: 'Driver "%s": Backend successfully created', $this->getDriverName()
65: )
66: );
67: return $result;
68: }
69:
70: /**
71: * Retrieves a list of mailboxes from the server.
72: *
73: * @return array The list of mailboxes.
74: */
75: public function listFolders()
76: {
77: $this->_logger->info(
78: sprintf('Driver "%s": Listing folders.', $this->getDriverName())
79: );
80: $result = parent::listFolders();
81: $this->_logger->info(
82: sprintf(
83: 'Driver "%s": List contained %s folders.',
84: $this->getDriverName(),
85: count($result))
86: );
87: return $result;
88: }
89:
90: /**
91: * Retrieves the specified annotation for the complete list of mailboxes.
92: *
93: * @param string $annotation The name of the annotation to retrieve.
94: *
95: * @return array An associative array combining the folder names as key with
96: * the corresponding annotation value.
97: */
98: public function listAnnotation($annotation)
99: {
100: $this->_logger->info(
101: sprintf('Driver "%s": Listing annotation "%s".', $this->getDriverName(), $annotation)
102: );
103: $result = parent::listAnnotation($annotation);
104: $this->_logger->info(
105: sprintf(
106: 'Driver "%s": List contained %s folder annotations.',
107: $this->getDriverName(),
108: count($result))
109: );
110: return $result;
111: }
112:
113: /**
114: * Retrieve the namespace information for this connection.
115: *
116: * @return Horde_Kolab_Storage_Driver_Namespace The initialized namespace handler.
117: */
118: public function getNamespace()
119: {
120: $this->_logger->info(
121: sprintf('Driver "%s": Retrieving namespaces.', $this->getDriverName())
122: );
123: $result = parent::getNamespace();
124: $this->_logger->info(
125: sprintf(
126: 'Driver "%s": Retrieved namespaces [%s].',
127: $this->getDriverName(),
128: (string)$result
129: )
130: );
131: return $result;
132: }
133: }