Continued:
[core.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@shipsimu.org>
7  * @version             0.0.0
8  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
9  * @license             GNU GPL 3.0 or any newer version
10  * @link                http://www.shipsimu.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          * Protected constructor
33          *
34          * @return      void
35          */
36         protected function __construct () {
37                 // Call parent constructor
38                 parent::__construct(__CLASS__);
39         }
40
41         /**
42          * Create a new web output system and set the content type
43          *
44          * @param       $contentType    A valid content-type
45          * @return      $debugInstance  An instance of this middleware class
46          */
47         public static final function createConsoleOutput ($contentType) {
48                 // Cast the content-type to string
49                 $contentType = (string) $contentType;
50                 $contentType = trim($contentType);
51
52                 // Get instance
53                 self::$consoleInstance = new ConsoleOutput();
54
55                 // Set the content type
56                 // @TODO Need to rewrite this to $requestInstance->addHeader()
57                 if (!empty($contentType)) {
58                         @header(sprintf('Content-type: %s',
59                                 $contentType
60                         ));
61                 } // END - if
62
63                 // Return instance
64                 return self::$consoleInstance;
65         }
66
67         /**
68          * Getter for an instance of this class
69          *
70          * @return      $consoleInstance        An instance of this class
71          */
72         public static final function getInstance() {
73                 // Is the self-instance already set?
74                 if (is_null(self::$consoleInstance)) {
75                         $contentType = FrameworkConfiguration::getSelfInstance()->getConfigEntry('web_content_type');
76                         self::$consoleInstance = ConsoleOutput::createConsoleOutput($contentType);
77                 } // END - if
78
79                 // Return the instance
80                 return self::$consoleInstance;
81         }
82
83         /**
84          * Output the code
85          *
86          * @param       $outStream      Something we shall sent to the console
87          * @param       $stripTags      Whether HTML tags shall be stripped out
88          * @return      void
89          */
90         public final function output ($outStream = FALSE, $stripTags = FALSE) {
91                 print trim($outStream) . PHP_EOL;
92         }
93
94         /**
95          * Determines seek position
96          *
97          * @return      $seekPosition   Current seek position
98          * @throws      UnsupportedOperationException   If this method is called
99          */
100         public function determineSeekPosition () {
101                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
102         }
103
104         /**
105          * Seek to given offset (default) or other possibilities as fseek() gives.
106          *
107          * @param       $offset         Offset to seek to (or used as "base" for other seeks)
108          * @param       $whence         Added to offset (default: only use offset to seek to)
109          * @return      $status         Status of file seek: 0 = success, -1 = failed
110          * @throws      UnsupportedOperationException   If this method is called
111          */
112         public function seek ($offset, $whence = SEEK_SET) {
113                 self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] offset=' . $offset . ',whence=' . $whence);
114                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
115         }
116
117         /**
118          * Size of file stack
119          *
120          * @return      $size   Size (in bytes) of file
121          * @throws      UnsupportedOperationException   If this method is called
122          */
123         public function size () {
124                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
125         }
126 }
127
128 // [EOF]
129 ?>