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