Continued:
[core.git] / framework / main / classes / output / debug / web / class_DebugWebOutput.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Output\Debug;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Debug\Debugger;
7 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
8 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
9 use Org\Mxchange\CoreFramework\Output\Debug\BaseDebugOutput;
10 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
11
12 /**
13  * A debug output class for the web browser
14  *
15  * @author              Roland Haeder <webmaster@shipsimu.org>
16  * @version             0.0.0
17  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 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 DebugWebOutput extends BaseDebugOutput implements Debugger, OutputStreamer {
35         /**
36          * Protected constructor
37          *
38          * @return      void
39          */
40         private 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 createDebugWebOutput () {
51                 // Get a new instance
52                 $debugInstance = new DebugWebOutput();
53
54                 // Return it
55                 return $debugInstance;
56         }
57
58         /**
59          * Outputs the given data directly, ignores $stripTags
60          *
61          * @param       $output         The HTML output
62          * @param       $stripTags      Whether HTML tags shall be stripped out
63          * @return      void
64          */
65         public final function outputStream (string $output, bool $stripTags = false) {
66                 // Strip out any <br />
67                 $output = str_replace('<br />', '', $output);
68                 printf('<!-- %s -->' . PHP_EOL, stripslashes($output));
69         }
70
71         /**
72          * Output the code
73          *
74          * @param       $outStream      Stream to output
75          * @param       $stripTags      Whether HTML tags shall be stripped out
76          * @return      void
77          */
78         public final function output (string $outStream = '', bool $stripTags = false) {
79                 // Empty output will be silently ignored
80                 if (!empty($outStream)) {
81                         $this->outputStream($outStream, $stripTags);
82                 }
83         }
84
85         /**
86          * Streams the data and maybe does something to it
87          *
88          * @param       $data   The data (string mostly) to "stream"
89          * @return      $data   The data (string mostly) to "stream"
90          * @throws      UnsupportedOperationException   If this method is called
91          */
92         public function streamData (string $data) {
93                 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.');
94                 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
95         }
96
97 }