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