3 namespace CoreFramework\Middleware\Debug;
5 // Import framework stuff
6 use CoreFramework\Factory\ObjectFactory;
7 use CoreFramework\Generic\NullPointerException;
8 use CoreFramework\Middleware\BaseMiddleware;
9 use CoreFramework\Registry\Registerable;
10 use CoreFramework\Stream\Output\OutputStreamer;
13 * The middlware debug output system. A *real* or concrete output class shall
14 * become registered with this middleware because the back-fall class will
15 * become deprecated soon.
17 * @author Roland Haeder <webmaster@shipsimu.org>
19 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
20 * @license GNU GPL 3.0 or any newer version
21 * @link http://www.shipsimu.org
22 * @deprecated See LoggerFactory for a more flexible approach
24 * This program is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 class DebugMiddleware extends BaseMiddleware implements Registerable {
39 * An instance of this class
41 private static $selfInstance = NULL;
44 * Protected constructor
48 protected function __construct () {
49 // Call parent constructor
50 parent::__construct(__CLASS__);
53 self::$selfInstance = $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
127 } elseif (is_null($this->getOutputInstance())) {
128 // Should not be NULL
129 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
132 // Use the output instance
133 $this->getOutputInstance()->outputStream($outStream, $stripTags);