]> git.mxchange.org Git - core.git/blob - inc/main/classes/output/debug/console/class_DebugConsoleOutput.php
Continued:
[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 use CoreFramework\Stream\Output\OutputStreamer;
10
11 /**
12  * A debug output class for the console (e.g. hub software)
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 DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStreamer, Registerable {
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 createDebugConsoleOutput () {
50                 // Get a new instance
51                 $debugInstance = new DebugConsoleOutput();
52
53                 // Return it
54                 return $debugInstance;
55         }
56
57         /**
58          * Outputs the given data without HTML tags
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                 // Strip HTML tags out?
66                 if ($stripTags === TRUE) {
67                         // Prepare the output without HTML tags
68                         $output = trim(html_entity_decode(strip_tags(stripslashes($output))));
69                 } else {
70                         // Prepare the output with HTML tags
71                         $output = trim(stripslashes($output));
72                 }
73
74                 // Are debug times enabled?
75                 if ($this->getConfigInstance()->getConfigEntry('debug_' . self::getResponseTypeFromSystem() . '_output_timings') == 'Y') {
76                         // Output it first
77                         $output = $this->getPrintableExecutionTime() . $output;
78                 } // END - if
79
80                 // And print it out...
81                 printf('%s%s', str_replace('-&gt;', '->', $output), PHP_EOL);
82         }
83
84         /**
85          * Output the code
86          *
87          * @param       $outStream      Stream to output
88          * @param       $stripTags      Whether HTML tags shall be stripped out
89          * @return      void
90          */
91         public final function output ($outStream = FALSE, $stripTags = FALSE) {
92                 // Empty output will be silently ignored
93                 if ($outStream !== FALSE) {
94                         $this->outputStream($outStream, $stripTags);
95                 } // END - if
96         }
97
98         /**
99          * Streams the data and maybe does something to it
100          *
101          * @param       $data   The data (string mostly) to "stream"
102          * @return      $data   The data (string mostly) to "stream"
103          * @throws      UnsupportedOperationException   If this method is called
104          */
105         public function streamData ($data) {
106                 self::createDebugInstance(__CLASS__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.');
107                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
108         }
109
110         /**
111          * Determines seek position
112          *
113          * @return      $seekPosition   Current seek position
114          * @throws      UnsupportedOperationException   If this method is called
115          */
116         public function determineSeekPosition () {
117                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
118         }
119
120         /**
121          * Seek to given offset (default) or other possibilities as fseek() gives.
122          *
123          * @param       $offset         Offset to seek to (or used as "base" for other seeks)
124          * @param       $whence         Added to offset (default: only use offset to seek to)
125          * @return      $status         Status of file seek: 0 = success, -1 = failed
126          * @throws      UnsupportedOperationException   If this method is called
127          */
128         public function seek ($offset, $whence = SEEK_SET) {
129                 self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] offset=' . $offset . ',whence=' . $whence);
130                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
131         }
132
133         /**
134          * Size of file stack
135          *
136          * @return      $size   Size (in bytes) of file
137          * @throws      UnsupportedOperationException   If this method is called
138          */
139         public function size () {
140                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
141         }
142
143 }