3 * This class simply puts text without any HTML code out. This class is suiable
6 * @author Roland Haeder <webmaster@mxchange.org>
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.mxchange.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();
41 private function __construct () {
42 // Call parent constructor
43 parent::constructor(__CLASS__);
46 $this->setObjectDescription("Console-Ausgabe-Handler");
48 // Create an unique ID
49 $this->createUniqueID();
53 * Create a new web output system and set the content type
55 * @param $contentType A valid content-type
56 * @return $debugInstance An instance of this middleware class
58 public final static function createConsoleOutput ($contentType) {
59 // Cast the content-type to string
60 $contentType = (string) $contentType;
61 $contentType = trim($contentType);
64 self::$consoleInstance = new ConsoleOutput();
66 // Set the content type
67 if (!empty($contentType)) {
68 @header(sprintf("Content-type: %s",
74 return self::$consoleInstance;
78 * Getter for an instance of this class
80 * @return $consoleInstance An instance of this class
82 public final static function getInstance() {
83 if (is_null(self::$consoleInstance)) {
84 $contentType = FrameworkConfiguration::getInstance()->readConfig("web_content_type");
85 self::$consoleInstance = ConsoleOutput::createConsoleOutput($contentType);
87 return self::$consoleInstance;
93 * @param $outStream Something we shall sent to the console
96 public final function output ($outStream=false) {
97 if ($outStream === false) {
98 // Output something here...
99 foreach ($this->vars as $var=>$value) {
100 $this->output("var=".$var.", value=".$value."");
103 // Output it to the console
104 printf("%s\n", trim(html_entity_decode(strip_tags($outStream))));
109 * Assigns a variable for output
111 * @param $var The variable we shall assign
112 * @param $value The value to store in the variable
115 public function assignVariable ($var, $value) {
116 $this->vars[$var] = $value;