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