8ed1c4f92524452fb4aad1b0af169af929cf2e28
[shipsimu.git] / inc / classes / main / output / class_WebOutput.php
1 <?php
2 /**
3  * This class simply puts HTML code / JavaScript code or CSS code out to the
4  * browser
5  *
6  * @author              Roland Haeder <webmaster@ship-simu.org>
7  * @version             0.0
8  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
9  * @license             GNU GPL 3.0 or any newer version
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24 class WebOutput extends BaseFrameworkSystem implements OutputStreamer {
25         /**
26          * The instance for the singleton design pattern
27          */
28         private static $webInstance = null;
29
30         /**
31          * Private constructor
32          *
33          * @return      void
34          */
35         private function __construct () {
36                 // Call parent constructor
37                 parent::constructor(__CLASS__);
38
39                 // Set description
40                 $this->setPartDescr("Web-Ausgabe-Handler");
41
42                 // Create an unique ID
43                 $this->createUniqueID();
44         }
45
46         /**
47          * Create a new web output system and set the content type
48          *
49          * @param               $contentType            A valid content-type
50          * @return      $debugInstance          An instance of this middleware class
51          */
52         public final static function createWebOutput ($contentType) {
53                 // Is there no instance?
54                 if (is_null(self::$webInstance)) {
55                         // Cast the content-type to string and trim it
56                         $contentType = (string) $contentType;
57                         $contentType = trim($contentType);
58
59                         // Set the content type
60                         if (!empty($contentType)) {
61                                 @header(sprintf("Content-type: %s",
62                                         $contentType
63                                 ));
64                         }
65
66                         // Get a new instance and set it
67                         self::$webInstance = new WebOutput();
68                 }
69
70                 // Return instance
71                 return self::$webInstance;
72         }
73
74         /**
75          * Assigns a variable for output
76          *
77          * @param               $var            The variable we shall assign
78          * @param               $value  The value to store in the variable
79          * @return      void
80          */
81         public function assignVariable($var, $value) {
82                 // Stub message because we don't have it here
83                 trigger_error(__METHOD__.": Stub!");
84         }
85
86         /**
87          * Output the code
88          *
89          * @return      void
90          */
91         public final function output ($outStream=false) {
92                 print $outStream;
93         }
94 }
95
96 // [EOF]
97 ?>