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