3 * This class simply puts text without any HTML code out. This class is suiable
6 * @author Roland Haeder <webmaster@ship-simu.org>
8 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.ship-simu.org
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.
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.
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/>.
25 class ConsoleOutput extends BaseFrameworkSystem implements OutputStreamer {
27 * The instance for the singleton design pattern
29 private static $consoleInstance = null;
34 private $vars = array();
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
47 * Create a new web output system and set the content type
49 * @param $contentType A valid content-type
50 * @return $debugInstance An instance of this middleware class
52 public final static function createConsoleOutput ($contentType) {
53 // Cast the content-type to string
54 $contentType = (string) $contentType;
55 $contentType = trim($contentType);
58 self::$consoleInstance = new ConsoleOutput();
60 // Set the content type
61 // @TODO Need to rewrite this to $requestInstance->addHeader()
62 if (!empty($contentType)) {
63 @header(sprintf("Content-type: %s",
69 return self::$consoleInstance;
73 * Getter for an instance of this class
75 * @return $consoleInstance An instance of this class
77 public final static function getInstance() {
78 if (is_null(self::$consoleInstance)) {
79 $contentType = FrameworkConfiguration::getInstance()->readConfig('web_content_type');
80 self::$consoleInstance = ConsoleOutput::createConsoleOutput($contentType);
82 return self::$consoleInstance;
88 * @param $outStream Something we shall sent to the console
91 public final function output ($outStream = false) {
92 if ($outStream === false) {
93 // Output something here...
94 foreach ($this->vars as $var => $value) {
95 $this->output("var=".$var.", value=".$value.'');
98 // Output it to the console
99 printf("%s\n", trim(html_entity_decode(strip_tags(stripslashes($outStream)))));
104 * Assigns a variable for output
106 * @param $var The variable we shall assign
107 * @param $value The value to store in the variable
110 public function assignVariable ($var, $value) {
111 $this->vars[$var] = $value;