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