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