3 * The middlware debug output system. A *real* or concrete output class shall
4 * become registered with this middleware because the back-fall class will
5 * become deprecated soon.
7 * @author Roland Haeder <webmaster@shipsimu.org>
9 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
10 * @license GNU GPL 3.0 or any newer version
11 * @link http://www.shipsimu.org
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 class DebugMiddleware extends BaseMiddleware implements Registerable {
28 * The concrete output instance
30 private $outputInstance = NULL;
33 * An instance of this class
35 private static $selfInstance = NULL;
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
47 self::$selfInstance = $this;
49 // Set it so all can use it
50 $this->setDebugInstance($this);
54 * Create a new debug output system.
55 * If no output is given this class is currently being used for back-fall.
56 * This fall-back mechanism will become deprecated very soon.
58 * @param $outputClass The class name which we shall use for
59 * registering the *real* debug output
60 * @param $className Class where a output should be created and
62 * @return $debugInstance An instance of this middleware class
64 public static final function createDebugMiddleware ($outputClass, $className) {
65 //* DEBUG-DIE: */ die(__METHOD__.': outputClass=' . $outputClass . ',className=' . $className);
67 // Create an instance if this middleware
68 $debugInstance = new DebugMiddleware();
70 // Default is that $outputClass may be invalid
71 $isInitialized = FALSE;
73 // Is there a valid output instance provided?
74 if ((!is_null($outputClass)) && (is_object($outputClass)) && ($outputClass instanceof OutputStreamer)) {
75 // Use the given output instance
76 $debugInstance->setOutputInstance($outputClass);
79 $isInitialized = TRUE;
80 } elseif ((!is_null($outputClass)) && (is_string($outputClass)) && (class_exists($outputClass))) {
81 // A name for a debug output class has been provided so we try to get it
82 $outputInstance = ObjectFactory::createObjectByName($outputClass);
84 // Set this as output class
85 $debugInstance->setOutputInstance($outputInstance);
88 $isInitialized = TRUE;
91 // Is the output class initialized?
92 if ($isInitialized === TRUE) {
93 // Then set class name
94 $debugInstance->getOutputInstance()->setLoggerClassName($className);
98 return $debugInstance;
102 * Getter for an instance of this class
104 * @return $selfInstance An instance of this class
106 public static final function getSelfInstance() {
107 return self::$selfInstance;
111 * Setter for output instance
113 * @param $outputInstance The debug output instance
116 public final function setOutputInstance (OutputStreamer $outputInstance) {
117 $this->outputInstance = $outputInstance;
121 * This method shall send debug output which can be HTML code for the
122 * browser or debug lines for a log file, etc. to the registered debug
125 * @param $outStream Data we shall 'stream' out to the world
126 * @param $stripTags Whether HTML tags shall be stripped out
129 public final function output ($outStream, $stripTags = FALSE) {
130 // Is the output stream set
131 if (empty($outStream)) {
132 // @TODO Initialization phase
136 // Use the output instance
137 $this->outputInstance->outputStream($outStream, $stripTags);