3 namespace CoreFramework\Debug\Output;
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;
13 * A debug output class for the console (e.g. hub software)
15 * @author Roland Haeder <webmaster@shipsimu.org>
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
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.
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.
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/>.
34 class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStreamer, Registerable {
36 * Protected constructor
40 protected function __construct () {
41 // Call parent constructor
42 parent::__construct(__CLASS__);
46 * Creates an instance of this class
48 * @return $debugInstance The prepared debug instance
50 public static final function createDebugConsoleOutput () {
52 $debugInstance = new DebugConsoleOutput();
55 return $debugInstance;
59 * Outputs the given data without HTML tags
61 * @param $output The HTML'ed output
62 * @param $stripTags Whether HTML tags shall be stripped out
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))));
72 // Are debug times enabled?
73 if ($this->getConfigInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings') == 'Y') {
75 $output = $this->getPrintableExecutionTime() . $output;
78 // And print it out...
79 printf('%s%s', str_replace('->', '->', $output), PHP_EOL);
85 * @param $outStream Stream to output
86 * @param $stripTags Whether HTML tags shall be stripped out
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);
97 * Streams the data and maybe does something to it
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
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);
109 * Determines seek position
111 * @return $seekPosition Current seek position
112 * @throws UnsupportedOperationException If this method is called
114 public function determineSeekPosition () {
115 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
119 * Seek to given offset (default) or other possibilities as fseek() gives.
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
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);
134 * @return $size Size (in bytes) of file
135 * @throws UnsupportedOperationException If this method is called
137 public function size () {
138 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);