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;
55 // Set it so all can use it
56 $this->setDebugInstance($this);
60 * Create a new debug output system.
61 * If no output is given this class is currently being used for back-fall.
62 * This fall-back mechanism will become deprecated very soon.
64 * @param $outputClass The class name which we shall use for
65 * registering the *real* debug output
66 * @param $className Class where a output should be created and
68 * @return $debugInstance An instance of this middleware class
70 public static final function createDebugMiddleware ($outputClass, $className) {
71 //* DEBUG-DIE: */ die(__METHOD__.': outputClass=' . $outputClass . ',className=' . $className);
73 // Create an instance if this middleware
74 $debugInstance = new DebugMiddleware();
76 // Default is that $outputClass may be invalid
77 $isInitialized = false;
79 // Is there a valid output instance provided?
80 if ((!is_null($outputClass)) && (is_object($outputClass)) && ($outputClass instanceof OutputStreamer)) {
81 // Use the given output instance
82 $debugInstance->setOutputInstance($outputClass);
85 $isInitialized = true;
86 } elseif ((!is_null($outputClass)) && (is_string($outputClass)) && (class_exists($outputClass))) {
87 // A name for a debug output class has been provided so we try to get it
88 $outputInstance = ObjectFactory::createObjectByName($outputClass);
90 // Set this as output class
91 $debugInstance->setOutputInstance($outputInstance);
94 $isInitialized = true;
97 // Is the output class initialized?
98 if ($isInitialized === true) {
99 // Then set class name
100 $debugInstance->getOutputInstance()->setLoggerClassName($className);
104 return $debugInstance;
108 * Getter for an instance of this class
110 * @return $selfInstance An instance of this class
112 public static final function getSelfInstance() {
113 return self::$selfInstance;
117 * This method shall send debug output which can be HTML code for the
118 * browser or debug lines for a log file, etc. to the registered debug
121 * @param $outStream Data we shall 'stream' out to the world
122 * @param $stripTags Whether HTML tags shall be stripped out
125 public final function output ($outStream, $stripTags = false) {
126 // Is the output stream set
127 if (empty($outStream)) {
128 // @TODO Initialization phase
130 } elseif (is_null($this->getOutputInstance())) {
131 // Should not be NULL
132 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
135 // Use the output instance
136 $this->getOutputInstance()->outputStream($outStream, $stripTags);