Rewrite continued:
[core.git] / framework / main / classes / output / web / class_WebOutput.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Output;
4
5 // Import framework stuff
6 use CoreFramework\Bootstrap\FrameworkBootstrap;
7 use CoreFramework\Manager\ManageableApplication;
8 use CoreFramework\Output\BaseOutput;
9 use CoreFramework\Registry\Registerable;
10 use CoreFramework\Stream\Output\OutputStreamer;
11
12 /**
13  * This class simply puts HTML code / JavaScript code or CSS code out to the
14  * browser
15  *
16  * @author              Roland Haeder <webmaster@shipsimu.org>
17  * @version             0.0.0
18  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
19  * @license             GNU GPL 3.0 or any newer version
20  * @link                http://www.shipsimu.org
21  *
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.
26  *
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.
31  *
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/>.
34  */
35 class WebOutput extends BaseOutput implements OutputStreamer, Registerable {
36         /**
37          * The instance for the singleton design pattern
38          */
39         private static $webInstance = NULL;
40
41         /**
42          * Protected constructor
43          *
44          * @return      void
45          */
46         protected function __construct () {
47                 // Call parent constructor
48                 parent::__construct(__CLASS__);
49         }
50
51         /**
52          * Create a new web output system and set the content type
53          *
54          * @param       $applicationInstance    An instance of a ManageableApplication class
55          * @return      $debugInstance                  An instance of this middleware class
56          */
57         public static final function createWebOutput (ManageableApplication $applicationInstance) {
58                 // Is the self-instance already set?
59                 if (is_null(self::$webInstance)) {
60                         // Get a new instance and set it
61                         self::$webInstance = new WebOutput();
62
63                         // Get the content type
64                         $contentType = self::$webInstance->getConfigInstance()->getConfigEntry('web_content_type');
65
66                         // Set the content type
67                         if (!empty($contentType)) {
68                                 // Set the header
69                                 FrameworkBootstrap::getResponseInstance()->addHeader('Content-type', $contentType);
70                         } // END - if
71                 } // END - if
72
73                 // Return instance
74                 return self::$webInstance;
75         }
76
77         /**
78          * Output the code
79          *
80          * @param       $outStream      Stream to output
81          * @param       $stripTags      Whether HTML tags shall be stripped out
82          * @return      void
83          */
84         public final function output ($outStream = false, $stripTags = false) {
85                 print(stripslashes($outStream));
86         }
87
88         /**
89          * Determines seek position
90          *
91          * @return      $seekPosition   Current seek position
92          * @throws      UnsupportedOperationException   If this method is called
93          */
94         public function determineSeekPosition () {
95                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
96         }
97
98         /**
99          * Seek to given offset (default) or other possibilities as fseek() gives.
100          *
101          * @param       $offset         Offset to seek to (or used as "base" for other seeks)
102          * @param       $whence         Added to offset (default: only use offset to seek to)
103          * @return      $status         Status of file seek: 0 = success, -1 = failed
104          * @throws      UnsupportedOperationException   If this method is called
105          */
106         public function seek ($offset, $whence = SEEK_SET) {
107                 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] offset=' . $offset . ',whence=' . $whence);
108                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
109         }
110
111         /**
112          * Size of file stack
113          *
114          * @return      $size   Size (in bytes) of file
115          * @throws      UnsupportedOperationException   If this method is called
116          */
117         public function size () {
118                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
119         }
120
121 }