]> git.mxchange.org Git - core.git/blob - inc/main/classes/output/console/class_ConsoleOutput.php
Continued:
[core.git] / inc / main / classes / output / console / class_ConsoleOutput.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Output;
4
5 // Import framework stuff
6 use CoreFramework\Configuration\FrameworkConfiguration;
7 use CoreFramework\Output\BaseOutput;
8
9 /**
10  * This class simply puts text without any HTML code out. This class is suiable
11  * for console output
12  *
13  * @author              Roland Haeder <webmaster@shipsimu.org>
14  * @version             0.0.0
15  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
16  * @license             GNU GPL 3.0 or any newer version
17  * @link                http://www.shipsimu.org
18  *
19  * This program is free software: you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation, either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  */
32 class ConsoleOutput extends BaseOutput implements OutputStreamer {
33         /**
34          * The instance for the singleton design pattern
35          */
36         private static $consoleInstance = NULL;
37
38         /**
39          * Protected constructor
40          *
41          * @return      void
42          */
43         protected function __construct () {
44                 // Call parent constructor
45                 parent::__construct(__CLASS__);
46         }
47
48         /**
49          * Create a new web output system and set the content type
50          *
51          * @param       $contentType    A valid content-type
52          * @return      $debugInstance  An instance of this middleware class
53          */
54         public static final function createConsoleOutput ($contentType) {
55                 // Cast the content-type to string
56                 $contentType = (string) $contentType;
57                 $contentType = trim($contentType);
58
59                 // Get instance
60                 self::$consoleInstance = new ConsoleOutput();
61
62                 // Set the content type
63                 // @TODO Need to rewrite this to $requestInstance->addHeader()
64                 if (!empty($contentType)) {
65                         @header(sprintf('Content-type: %s',
66                                 $contentType
67                         ));
68                 } // END - if
69
70                 // Return instance
71                 return self::$consoleInstance;
72         }
73
74         /**
75          * Getter for an instance of this class
76          *
77          * @return      $consoleInstance        An instance of this class
78          */
79         public static final function getInstance() {
80                 // Is the self-instance already set?
81                 if (is_null(self::$consoleInstance)) {
82                         $contentType = FrameworkConfiguration::getSelfInstance()->getConfigEntry('web_content_type');
83                         self::$consoleInstance = ConsoleOutput::createConsoleOutput($contentType);
84                 } // END - if
85
86                 // Return the instance
87                 return self::$consoleInstance;
88         }
89
90         /**
91          * Output the code
92          *
93          * @param       $outStream      Something we shall sent to the console
94          * @param       $stripTags      Whether HTML tags shall be stripped out
95          * @return      void
96          */
97         public final function output ($outStream = FALSE, $stripTags = FALSE) {
98                 print trim($outStream) . PHP_EOL;
99         }
100
101         /**
102          * Determines seek position
103          *
104          * @return      $seekPosition   Current seek position
105          * @throws      UnsupportedOperationException   If this method is called
106          */
107         public function determineSeekPosition () {
108                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
109         }
110
111         /**
112          * Seek to given offset (default) or other possibilities as fseek() gives.
113          *
114          * @param       $offset         Offset to seek to (or used as "base" for other seeks)
115          * @param       $whence         Added to offset (default: only use offset to seek to)
116          * @return      $status         Status of file seek: 0 = success, -1 = failed
117          * @throws      UnsupportedOperationException   If this method is called
118          */
119         public function seek ($offset, $whence = SEEK_SET) {
120                 self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] offset=' . $offset . ',whence=' . $whence);
121                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
122         }
123
124         /**
125          * Size of file stack
126          *
127          * @return      $size   Size (in bytes) of file
128          * @throws      UnsupportedOperationException   If this method is called
129          */
130         public function size () {
131                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
132         }
133
134 }