3 namespace Org\Mxchange\CoreFramework\Debug\Output;
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;
14 * A debug output class for the console (e.g. hub software)
16 * @author Roland Haeder <webmaster@shipsimu.org>
18 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 Core Developer Team
19 * @license GNU GPL 3.0 or any newer version
20 * @link http://www.shipsimu.org
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.
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.
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/>.
35 class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStreamer, Registerable {
37 * Cached configuration entry 'debug_*_output_timings'
39 private $isDebugOutputTimingsEnabled = FALSE;
42 * Protected constructor
46 private function __construct () {
47 // Call parent constructor first
48 parent::__construct(__CLASS__);
50 // Cache configuration entry
51 $this->isDebugOutputTimingsEnabled = FrameworkBootstrap::getConfigurationInstance()->isEnabled('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings');
55 * Creates an instance of this class
57 * @return $debugInstance The prepared debug instance
59 public static final function createDebugConsoleOutput () {
61 $debugInstance = new DebugConsoleOutput();
64 return $debugInstance;
68 * Outputs the given data without HTML tags
70 * @param $output The HTML'ed output
71 * @param $stripTags Whether HTML tags shall be stripped out
74 public final function outputStream (string $output, bool $stripTags = false) {
75 // Strip HTML tags out?
76 if ($stripTags === true) {
77 // Prepare the output without HTML tags
78 $output = trim(html_entity_decode(strip_tags(stripslashes($output))));
81 // Are debug times enabled?
82 if ($this->isDebugOutputTimingsEnabled) {
84 $output = $this->getPrintableExecutionTime() . $output;
87 // And print it out...
88 printf('%s%s', str_replace('->', '->', $output), PHP_EOL);
94 * @param $outStream Stream to output
95 * @param $stripTags Whether HTML tags shall be stripped out
98 public final function output (string $outStream = '', bool $stripTags = false) {
99 // Empty output will be silently ignored
100 if (!empty($outStream)) {
101 $this->outputStream($outStream, $stripTags);
106 * Streams the data and maybe does something to it
108 * @param $data The data (string mostly) to "stream"
109 * @return $data The data (string mostly) to "stream"
110 * @throws UnsupportedOperationException If this method is called
112 public function streamData (string $data) {
113 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.');
114 throw new UnsupportedOperationException([$this, __FUNCTION__], self::EXCEPTION_UNSPPORTED_OPERATION);