374c2af4ae7182f3574f83847f5c779ea53221c3
[mailer.git] / inc / classes / main / output / class_ConsoleOutput.php
1 <?php
2 /**
3  * This class simply puts text without any HTML code out. This class is suiable
4  * for console output
5  *
6  * @author              Roland Haeder <webmaster@mxchange.org>
7  * @version             0.3.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.mxchange.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 ConsoleOutput extends BaseFrameworkSystem implements OutputStreamer {
26         /**
27          * The instance for the singleton design pattern
28          */
29         private static $consoleInstance = null;
30
31         /**
32          * Assigned variables
33          */
34         private $vars = array();
35
36         /**
37          * Private constructor
38          *
39          * @return      void
40          */
41         private function __construct () {
42                 // Call parent constructor
43                 parent::constructor(__CLASS__);
44
45                 // Set description
46                 $this->setPartDescr("Console-Ausgabe-Handler");
47
48                 // Create an unique ID
49                 $this->createUniqueID();
50         }
51
52         /**
53          * Create a new web output system and set the content type
54          *
55          * @param               $contentType            A valid content-type
56          * @return      $debugInstance          An instance of this middleware class
57          */
58         public final static function createConsoleOutput ($contentType) {
59                 // Cast the content-type to string
60                 $contentType = (string) $contentType;
61                 $contentType = trim($contentType);
62
63                 // Get instance
64                 self::$consoleInstance = new ConsoleOutput();
65
66                 // Set the content type
67                 if (!empty($contentType)) {
68                         @header(sprintf("Content-type: %s",
69                                 $contentType
70                         ));
71                 }
72
73                 // Return instance
74                 return self::$consoleInstance;
75         }
76
77         /**
78          * Getter for an instance of this class
79          *
80          * @return      $consoleInstance                An instance of this class
81          */
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);
86                 }
87                 return self::$consoleInstance;
88         }
89
90         /**
91          * Output the code
92          *
93          * @param               $outStream      Something we shall sent to the console
94          * @return      void
95          */
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."");
101                         }
102                 } else {
103                         // Output it to the console
104                         printf("%s\n", trim(html_entity_decode(strip_tags($outStream))));
105                 }
106         }
107
108         /**
109          * Assigns a variable for output
110          *
111          * @param               $var            The variable we shall assign
112          * @param               $value  The value to store in the variable
113          * @return      void
114          */
115         public function assignVariable ($var, $value) {
116                 $this->vars[$var] = $value;
117         }
118 }
119
120 // [EOF]
121 ?>