3 namespace CoreFramework\Middleware\Debug;
5 // Import framework stuff
6 use CoreFramework\Factory\ObjectFactory;
7 use CoreFramework\Middleware\BaseMiddleware;
8 use CoreFramework\Registry\Registerable;
11 * The middlware debug output system. A *real* or concrete output class shall
12 * become registered with this middleware because the back-fall class will
13 * become deprecated soon.
15 * @author Roland Haeder <webmaster@shipsimu.org>
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
18 * @license GNU GPL 3.0 or any newer version
19 * @link http://www.shipsimu.org
20 * @deprecated See LoggerFactory for a more flexible approach
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 class DebugMiddleware extends BaseMiddleware implements Registerable {
37 * An instance of this class
39 private static $selfInstance = NULL;
42 * Protected constructor
46 protected function __construct () {
47 // Call parent constructor
48 parent::__construct(__CLASS__);
51 self::$selfInstance = $this;
53 // Set it so all can use it
54 $this->setDebugInstance($this);
58 * Create a new debug output system.
59 * If no output is given this class is currently being used for back-fall.
60 * This fall-back mechanism will become deprecated very soon.
62 * @param $outputClass The class name which we shall use for
63 * registering the *real* debug output
64 * @param $className Class where a output should be created and
66 * @return $debugInstance An instance of this middleware class
68 public static final function createDebugMiddleware ($outputClass, $className) {
69 //* DEBUG-DIE: */ die(__METHOD__.': outputClass=' . $outputClass . ',className=' . $className);
71 // Create an instance if this middleware
72 $debugInstance = new DebugMiddleware();
74 // Default is that $outputClass may be invalid
75 $isInitialized = FALSE;
77 // Is there a valid output instance provided?
78 if ((!is_null($outputClass)) && (is_object($outputClass)) && ($outputClass instanceof OutputStreamer)) {
79 // Use the given output instance
80 $debugInstance->setOutputInstance($outputClass);
83 $isInitialized = TRUE;
84 } elseif ((!is_null($outputClass)) && (is_string($outputClass)) && (class_exists($outputClass))) {
85 // A name for a debug output class has been provided so we try to get it
86 $outputInstance = ObjectFactory::createObjectByName($outputClass);
88 // Set this as output class
89 $debugInstance->setOutputInstance($outputInstance);
92 $isInitialized = TRUE;
95 // Is the output class initialized?
96 if ($isInitialized === TRUE) {
97 // Then set class name
98 $debugInstance->getOutputInstance()->setLoggerClassName($className);
102 return $debugInstance;
106 * Getter for an instance of this class
108 * @return $selfInstance An instance of this class
110 public static final function getSelfInstance() {
111 return self::$selfInstance;
115 * This method shall send debug output which can be HTML code for the
116 * browser or debug lines for a log file, etc. to the registered debug
119 * @param $outStream Data we shall 'stream' out to the world
120 * @param $stripTags Whether HTML tags shall be stripped out
123 public final function output ($outStream, $stripTags = FALSE) {
124 // Is the output stream set
125 if (empty($outStream)) {
126 // @TODO Initialization phase
130 // Use the output instance
131 $this->getOutputInstance()->outputStream($outStream, $stripTags);