3 * This class simply puts HTML code / JavaScript code or CSS code out to the
6 * @author Roland Haeder <webmaster@ship-simu.org>
8 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
9 * @license GNU GPL 3.0 or any newer version
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.
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.
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/>.
24 class ConsoleOutput extends BaseFrameworkSystem implements OutputStreamer {
26 * The instance for the singleton design pattern
28 private static $consoleInstance = null;
33 private $vars = array();
40 private function __construct () {
41 // Call parent constructor
42 parent::constructor(__CLASS__);
45 $this->setPartDescr("Console-Ausgabe-Handler");
47 // Create an unique ID
48 $this->createUniqueID();
52 * Create a new web output system and set the content type
54 * @param $contentType A valid content-type
55 * @return $debugInstance An instance of this middleware class
57 public final static function createConsoleOutput ($contentType) {
58 // Cast the content-type to string
59 $contentType = (string) $contentType;
60 $contentType = trim($contentType);
63 self::$consoleInstance = new ConsoleOutput();
65 // Set the content type
66 if (!empty($contentType)) {
67 @header(sprintf("Content-type: %s",
73 return self::$consoleInstance;
77 * Getter for an instance of this class
79 * @return $consoleInstance An instance of this class
81 public final static function getInstance() {
82 if (is_null(self::$consoleInstance)) {
83 $contentType = FrameworkConfiguration::getInstance()->readConfig("web_content_type");
84 self::$consoleInstance = ConsoleOutput::createConsoleOutput($contentType);
86 return self::$consoleInstance;
92 * @param $outStream Something we shall sent to the console
95 public final function output ($outStream=false) {
96 if ($outStream === false) {
97 // Output something here...
98 foreach ($this->vars as $var=>$value) {
99 $this->output("var=".$var.", value=".$value."");
102 // Output it to the console
103 printf("%s\n", trim(html_entity_decode(strip_tags($outStream))));
108 * Assigns a variable for output
110 * @param $var The variable we shall assign
111 * @param $value The value to store in the variable
114 public function assignVariable ($var, $value) {
115 $this->vars[$var] = $value;