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