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