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 - 2017 Core Developer Team
10 * @license GNU GPL 3.0 or any newer version
11 * @link http://www.shipsimu.org
12 * @deprecated See LoggerFactory for a more flexible approach
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 class DebugMiddleware extends BaseMiddleware implements Registerable {
29 * An instance of this class
31 private static $selfInstance = NULL;
34 * Protected constructor
38 protected function __construct () {
39 // Call parent constructor
40 parent::__construct(__CLASS__);
43 self::$selfInstance = $this;
45 // Set it so all can use it
46 $this->setDebugInstance($this);
50 * Create a new debug output system.
51 * If no output is given this class is currently being used for back-fall.
52 * This fall-back mechanism will become deprecated very soon.
54 * @param $outputClass The class name which we shall use for
55 * registering the *real* debug output
56 * @param $className Class where a output should be created and
58 * @return $debugInstance An instance of this middleware class
60 public static final function createDebugMiddleware ($outputClass, $className) {
61 //* DEBUG-DIE: */ die(__METHOD__.': outputClass=' . $outputClass . ',className=' . $className);
63 // Create an instance if this middleware
64 $debugInstance = new DebugMiddleware();
66 // Default is that $outputClass may be invalid
67 $isInitialized = FALSE;
69 // Is there a valid output instance provided?
70 if ((!is_null($outputClass)) && (is_object($outputClass)) && ($outputClass instanceof OutputStreamer)) {
71 // Use the given output instance
72 $debugInstance->setOutputInstance($outputClass);
75 $isInitialized = TRUE;
76 } elseif ((!is_null($outputClass)) && (is_string($outputClass)) && (class_exists($outputClass))) {
77 // A name for a debug output class has been provided so we try to get it
78 $outputInstance = ObjectFactory::createObjectByName($outputClass);
80 // Set this as output class
81 $debugInstance->setOutputInstance($outputInstance);
84 $isInitialized = TRUE;
87 // Is the output class initialized?
88 if ($isInitialized === TRUE) {
89 // Then set class name
90 $debugInstance->getOutputInstance()->setLoggerClassName($className);
94 return $debugInstance;
98 * Getter for an instance of this class
100 * @return $selfInstance An instance of this class
102 public static final function getSelfInstance() {
103 return self::$selfInstance;
107 * This method shall send debug output which can be HTML code for the
108 * browser or debug lines for a log file, etc. to the registered debug
111 * @param $outStream Data we shall 'stream' out to the world
112 * @param $stripTags Whether HTML tags shall be stripped out
115 public final function output ($outStream, $stripTags = FALSE) {
116 // Is the output stream set
117 if (empty($outStream)) {
118 // @TODO Initialization phase
122 // Use the output instance
123 $this->getOutputInstance()->outputStream($outStream, $stripTags);