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