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