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