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