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