3 namespace Org\Mxchange\CoreFramework\Middleware\Debug;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
7 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
8 use Org\Mxchange\CoreFramework\Middleware\BaseMiddleware;
9 use Org\Mxchange\CoreFramework\Registry\Registerable;
10 use Org\Mxchange\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 <<<<<<< HEAD:framework/main/middleware/debug/class_DebugMiddleware.php
20 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
22 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
23 >>>>>>> Some updates::inc/main/middleware/debug/class_DebugMiddleware.php
24 * @license GNU GPL 3.0 or any newer version
25 * @link http://www.shipsimu.org
26 * @deprecated See LoggerFactory for a more flexible approach
28 * This program is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, either version 3 of the License, or
31 * (at your option) any later version.
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
38 * You should have received a copy of the GNU General Public License
39 * along with this program. If not, see <http://www.gnu.org/licenses/>.
41 class DebugMiddleware extends BaseMiddleware implements Registerable {
43 * An instance of this class
45 private static $selfInstance = NULL;
48 * Protected constructor
52 protected function __construct () {
53 // Call parent constructor
54 parent::__construct(__CLASS__);
57 self::$selfInstance = $this;
61 * Create a new debug output system.
62 * If no output is given this class is currently being used for back-fall.
63 * This fall-back mechanism will become deprecated very soon.
65 * @param $outputClass The class name which we shall use for
66 * registering the *real* debug output
67 * @param $className Class where a output should be created and
69 * @return $debugInstance An instance of this middleware class
71 public static final function createDebugMiddleware ($outputClass, $className) {
72 //* DEBUG-DIE: */ die(__METHOD__.': outputClass=' . $outputClass . ',className=' . $className);
74 // Create an instance if this middleware
75 $debugInstance = new DebugMiddleware();
77 // Default is that $outputClass may be invalid
78 $isInitialized = false;
80 // Is there a valid output instance provided?
81 if ((!is_null($outputClass)) && (is_object($outputClass)) && ($outputClass instanceof OutputStreamer)) {
82 // Use the given output instance
83 $debugInstance->setOutputInstance($outputClass);
86 $isInitialized = true;
87 } elseif ((!is_null($outputClass)) && (is_string($outputClass)) && (class_exists($outputClass))) {
88 // A name for a debug output class has been provided so we try to get it
89 $outputInstance = ObjectFactory::createObjectByName($outputClass);
91 // Set this as output class
92 $debugInstance->setOutputInstance($outputInstance);
95 $isInitialized = true;
98 // Is the output class initialized?
99 if ($isInitialized === true) {
100 // Then set class name
101 $debugInstance->getOutputInstance()->setLoggerClassName($className);
105 return $debugInstance;
109 * Getter for an instance of this class
111 * @return $selfInstance An instance of this class
113 public static final function getSelfInstance() {
114 return self::$selfInstance;
118 * This method shall send debug output which can be HTML code for the
119 * browser or debug lines for a log file, etc. to the registered debug
122 * @param $outStream Data we shall 'stream' out to the world
123 * @param $stripTags Whether HTML tags shall be stripped out
126 public final function output ($outStream, $stripTags = false) {
127 // Is the output stream set
128 if (empty($outStream)) {
129 // @TODO Initialization phase
131 } elseif (is_null($this->getOutputInstance())) {
132 // Should not be NULL
133 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
136 // Use the output instance
137 $this->getOutputInstance()->outputStream($outStream, $stripTags);