1: <?php
2:
3: /*
4: * This file is part of SwiftMailer.
5: * (c) 2004-2009 Chris Corbyn
6: *
7: * For the full copyright and license information, please view the LICENSE
8: * file that was distributed with this source code.
9: */
10:
11: /**
12: * Logs to an Array backend.
13: * @package Swift
14: * @subpackage Transport
15: * @author Chris Corbyn
16: */
17: class Swift_Plugins_Loggers_ArrayLogger implements Swift_Plugins_Logger
18: {
19: /**
20: * The log contents.
21: * @var array
22: * @access private
23: */
24: private $_log = array();
25:
26: /**
27: * Max size of the log.
28: * @var int
29: * @access private
30: */
31: private $_size = 0;
32:
33: /**
34: * Create a new ArrayLogger with a maximum of $size entries.
35: * @var int $size
36: */
37: public function __construct($size = 50)
38: {
39: $this->_size = $size;
40: }
41:
42: /**
43: * Add a log entry.
44: * @param string $entry
45: */
46: public function add($entry)
47: {
48: $this->_log[] = $entry;
49: while (count($this->_log) > $this->_size) {
50: array_shift($this->_log);
51: }
52: }
53:
54: /**
55: * Clear the log contents.
56: */
57: public function clear()
58: {
59: $this->_log = array();
60: }
61:
62: /**
63: * Get this log as a string.
64: * @return string
65: */
66: public function dump()
67: {
68: return implode(PHP_EOL, $this->_log);
69: }
70: }
71: