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