1: <?php
2: /**
3: * This file contains the log file writer class.
4: *
5: * @package Core
6: * @subpackage Log
7: * @version SVN Revision $Rev:$
8: *
9: * @author Dominik Ziegler
10: * @copyright four for business AG <www.4fb.de>
11: * @license http://www.contenido.org/license/LIZENZ.txt
12: * @link http://www.4fb.de
13: * @link http://www.contenido.org
14: */
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: /**
19: * This class contains the file writer class for the logging mechanism.
20: *
21: * @package Core
22: * @subpackage Log
23: */
24: class cLogWriterFile extends cLogWriter {
25: /**
26: * @var resource Destination handle
27: */
28: protected $_handle = NULL;
29:
30: /**
31: * Constructor of the writer instance.
32: * @param array $options Array with options for the writer instance (optional)
33: */
34: public function __construct($options = array()) {
35: parent::__construct($options);
36:
37: $this->_createHandle();
38: }
39:
40: /**
41: * Checks destination and creates the handle for the write process.
42: *
43: * @throws cException if not destination is specified
44: * @throws cFileNotFoundException if the destination file could not be read
45: */
46: protected function _createHandle() {
47: $destination = $this->getOption('destination');
48: if ($destination == '') {
49: throw new cException('No destination was specified.');
50: }
51:
52: if (($this->_handle = fopen($destination, 'a')) === false) {
53: throw new cFileNotFoundException('Destination handle could not be created.');
54: }
55: }
56:
57: /**
58: * Writes the content to file handle.
59: *
60: * @param string $message Message to write
61: * @param int $priority Priority of the log entry
62: * @return boolean State of the write process
63: */
64: public function write($message, $priority) {
65: return (fwrite($this->_handle, $message) != false);
66: }
67: }
68: