1: <?php
2: /**
3: * A stop watch decorator for outgoing requests from 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 stop watch decorator for outgoing requests from 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_Timer
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: * A stop watch.
40: *
41: * @var Horde_Support_Timer
42: */
43: private $_timer;
44:
45: /**
46: * Constructor.
47: *
48: * @param Horde_Kolab_Storage_Driver $driver The decorated driver.
49: * @param Horde_Support_Timer $timer A stop watch.
50: * @param mixed $logger The log handler. This instance
51: * must provide the info() method.
52: */
53: public function __construct(Horde_Kolab_Storage_Driver $driver,
54: Horde_Support_Timer $timer,
55: $logger)
56: {
57: $this->_logger = $logger;
58: $this->_timer = $timer;
59: parent::__construct($driver);
60: }
61:
62: /**
63: * Create the backend driver.
64: *
65: * @return mixed The backend driver.
66: */
67: public function createBackend()
68: {
69: $this->_timer->push();
70: $result = parent::createBackend();
71: $this->_logger->info(
72: sprintf(
73: 'REQUEST OUT IMAP: %s ms [construct]',
74: floor($this->_timer->pop() * 1000)
75: )
76: );
77: return $result;
78: }
79:
80: /**
81: * Retrieves a list of mailboxes from the server.
82: *
83: * @return array The list of mailboxes.
84: */
85: public function listFolders()
86: {
87: $this->_timer->push();
88: $result = parent::listFolders();
89: $this->_logger->info(
90: sprintf(
91: 'REQUEST OUT IMAP: %s ms [listFolders]',
92: floor($this->_timer->pop() * 1000)
93: )
94: );
95: return $result;
96: }
97:
98: /**
99: * Retrieves the specified annotation for the complete list of mailboxes.
100: *
101: * @param string $annotation The name of the annotation to retrieve.
102: *
103: * @return array An associative array combining the folder names as key with
104: * the corresponding annotation value.
105: */
106: public function listAnnotation($annotation)
107: {
108: $this->_timer->push();
109: $result = parent::listAnnotation($annotation);
110: $this->_logger->info(
111: sprintf(
112: 'REQUEST OUT IMAP: %s ms [listAnnotation]',
113: floor($this->_timer->pop() * 1000)
114: )
115: );
116: return $result;
117: }
118:
119: /**
120: * Retrieve the namespace information for this connection.
121: *
122: * @return Horde_Kolab_Storage_Driver_Namespace The initialized namespace handler.
123: */
124: public function getNamespace()
125: {
126: $this->_timer->push();
127: $result = parent::getNamespace();
128: $this->_logger->info(
129: sprintf(
130: 'REQUEST OUT IMAP: %s ms [getNamespace]',
131: floor($this->_timer->pop() * 1000)
132: )
133: );
134: return $result;
135: }
136: }