3 namespace Org\Mxchange\CoreFramework\Output;
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;
12 * This class simply puts text without any HTML code out. This class is suiable
15 * @author Roland Haeder <webmaster@shipsimu.org>
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
18 * @license GNU GPL 3.0 or any newer version
19 * @link http://www.shipsimu.org
21 * This program is free software: you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation, either version 3 of the License, or
24 * (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 class ConsoleOutput extends BaseOutput implements OutputStreamer {
36 * The instance for the singleton design pattern
38 private static $consoleInstance = NULL;
41 * Protected constructor
45 protected function __construct () {
46 // Call parent constructor
47 parent::__construct(__CLASS__);
51 * Create a new web output system and set the content type
53 * @param $contentType A valid content-type
54 * @return $debugInstance An instance of this middleware class
56 public static final function createConsoleOutput (string $contentType) {
57 // Cast the content-type to string
58 $contentType = trim($contentType);
61 self::$consoleInstance = new ConsoleOutput();
63 // Set the content type
64 // @TODO Need to rewrite this to $requestInstance->addHeader()
65 if (!empty($contentType)) {
66 @header(sprintf('Content-type: %s',
72 return self::$consoleInstance;
76 * Getter for an instance of this class
78 * @return $consoleInstance An instance of this class
80 public static final function getInstance() {
81 // Is the self-instance already set?
82 if (is_null(self::$consoleInstance)) {
83 $contentType = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('web_content_type');
84 self::$consoleInstance = ConsoleOutput::createConsoleOutput($contentType);
87 // Return the instance
88 return self::$consoleInstance;
94 * @param $outStream Something we shall sent to the console
95 * @param $stripTags Whether HTML tags shall be stripped out
98 public final function output (string $outStream = '', bool $stripTags = false) {
99 print trim($outStream) . PHP_EOL;