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