Continued with renaming-season:
[core.git] / framework / main / classes / output / debug / error / class_DebugErrorLogOutput.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Output\Debug;
4
5 // Import framework stuff
6 use CoreFramework\Debug\Debugger;
7 use CoreFramework\Output\Debug\BaseDebugOutput;
8 use CoreFramework\Stream\Output\OutputStreamer;
9
10 /**
11  * A debug output class for PHP's error_log() command
12  *
13  * @author              Roland Haeder <webmaster@shipsimu.org>
14  * @version             0.0.0
15  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
16  * @license             GNU GPL 3.0 or any newer version
17  * @link                http://www.shipsimu.org
18  *
19  * This program is free software: you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation, either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  */
32 class DebugErrorLogOutput extends BaseDebugOutput implements Debugger, OutputStreamer {
33         /**
34          * Protected constructor
35          *
36          * @return      void
37          */
38         protected function __construct () {
39                 // Call parent constructor
40                 parent::__construct(__CLASS__);
41         }
42
43         /**
44          * Creates an instance of this class
45          *
46          * @return      $debugInstance  The prepared debug instance
47          */
48         public static final function createDebugErrorLogOutput () {
49                 // Get a new instance
50                 $debugInstance = new DebugErrorLogOutput();
51
52                 // Return it
53                 return $debugInstance;
54         }
55
56         /**
57          * Outputs the given data without HTML tags, ignores $stripTags
58          *
59          * @param       $output         The HTML'ed output
60          * @param       $stripTags      Whether HTML tags shall be stripped out
61          * @return      void
62          */
63         public final function outputStream ($output, $stripTags = FALSE) {
64                 // Split multiple lines into and array to put them out line-by-line
65                 $errorLines = explode(chr(10), $output);
66
67                 // "Walk" through all lines
68                 foreach ($errorLines as $err) {
69                         // Trim any spaces, \n, \r etc. out
70                         $err = trim($err);
71
72                         // Log only none-empty lines
73                         if (!empty($err)) {
74                                 // Log this line
75                                 error_log(html_entity_decode(strip_tags($err)), 0);
76                         } // END - if
77                 } // END - foreach
78         }
79
80         /**
81          * Output the code
82          *
83          * @param       $outStream      Stream to output
84          * @param       $stripTags      Whether HTML tags shall be stripped out
85          * @return      void
86          */
87         public final function output ($outStream = FALSE, $stripTags = FALSE) {
88                 // Empty output will be silently ignored
89                 if ($outStream !== FALSE) {
90                         $this->outputStream($outStream);
91                 }
92         }
93
94         /**
95          * Streams the data and maybe does something to it
96          *
97          * @param       $data   The data (string mostly) to "stream"
98          * @return      $data   The data (string mostly) to "stream"
99          * @throws      UnsupportedOperationException   If this method is called
100          */
101         public function streamData ($data) {
102                 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.');
103                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
104         }
105
106         /**
107          * Determines for seek position
108          *
109          * @return      $seekPosition   Current seek position
110          * @throws      UnsupportedOperationException   If this method is called
111          */
112         public function determineSeekPosition () {
113                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
114         }
115
116         /**
117          * Seek to given offset (default) or other possibilities as fseek() gives.
118          *
119          * @param       $offset         Offset to seek to (or used as "base" for other seeks)
120          * @param       $whence         Added to offset (default: only use offset to seek to)
121          * @return      $status         Status of file seek: 0 = success, -1 = failed
122          * @throws      UnsupportedOperationException   If this method is called
123          */
124         public function seek ($offset, $whence = SEEK_SET) {
125                 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] offset=' . $offset . ',whence=' . $whence);
126                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
127         }
128
129         /**
130          * Size of file stack
131          *
132          * @return      $size   Size (in bytes) of file
133          * @throws      UnsupportedOperationException   If this method is called
134          */
135         public function size () {
136                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
137         }
138
139 }