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