]> git.mxchange.org Git - core.git/blob - inc/main/classes/output/debug/console/class_DebugConsoleOutput.php
8ab0887b03b17de6e60370bbf79d5867e526c59e
[core.git] / inc / main / classes / output / debug / console / class_DebugConsoleOutput.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Debug\Output;
4
5 // Import framework stuff
6 use CoreFramework\Registry\Registerable;
7
8 /**
9  * A debug output class for the console (e.g. hub software)
10  *
11  * @author              Roland Haeder <webmaster@shipsimu.org>
12  * @version             0.0.0
13  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
14  * @license             GNU GPL 3.0 or any newer version
15  * @link                http://www.shipsimu.org
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program. If not, see <http://www.gnu.org/licenses/>.
29  */
30 class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStreamer, Registerable {
31         /**
32          * Protected constructor
33          *
34          * @return      void
35          */
36         protected function __construct () {
37                 // Call parent constructor
38                 parent::__construct(__CLASS__);
39         }
40
41         /**
42          * Creates an instance of this class
43          *
44          * @return      $debugInstance  The prepared debug instance
45          */
46         public static final function createDebugConsoleOutput () {
47                 // Get a new instance
48                 $debugInstance = new DebugConsoleOutput();
49
50                 // Return it
51                 return $debugInstance;
52         }
53
54         /**
55          * Outputs the given data without HTML tags
56          *
57          * @param       $output         The HTML'ed output
58          * @param       $stripTags      Whether HTML tags shall be stripped out
59          * @return      void
60          */
61         public final function outputStream ($output, $stripTags = FALSE) {
62                 // Strip HTML tags out?
63                 if ($stripTags === TRUE) {
64                         // Prepare the output without HTML tags
65                         $output = trim(html_entity_decode(strip_tags(stripslashes($output))));
66                 } else {
67                         // Prepare the output with HTML tags
68                         $output = trim(stripslashes($output));
69                 }
70
71                 // Are debug times enabled?
72                 if ($this->getConfigInstance()->getConfigEntry('debug_' . self::getResponseTypeFromSystem() . '_output_timings') == 'Y') {
73                         // Output it first
74                         $output = $this->getPrintableExecutionTime() . $output;
75                 } // END - if
76
77                 // And print it out...
78                 printf('%s%s', str_replace('-&gt;', '->', $output), PHP_EOL);
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, $stripTags);
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__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.');
104                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
105         }
106
107         /**
108          * Determines 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__)->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
141 // [EOF]
142 ?>