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