]> git.mxchange.org Git - core.git/blobdiff - inc/main/middleware/debug/class_DebugMiddleware.php
Renamed classes/main/ to main/classes/ + added FuseFeature, an upcoming feature
[core.git] / inc / main / middleware / debug / class_DebugMiddleware.php
diff --git a/inc/main/middleware/debug/class_DebugMiddleware.php b/inc/main/middleware/debug/class_DebugMiddleware.php
new file mode 100644 (file)
index 0000000..045a330
--- /dev/null
@@ -0,0 +1,128 @@
+<?php
+/**
+ * The middlware debug output system. A *real* or concrete output class shall
+ * become registered with this middleware because the back-fall class will
+ * become deprecated soon.
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.shipsimu.org
+ * @deprecated See LoggerFactory for a more flexible approach
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class DebugMiddleware extends BaseMiddleware implements Registerable {
+       /**
+        * An instance of this class
+        */
+       private static $selfInstance = NULL;
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set own instance
+               self::$selfInstance = $this;
+
+               // Set it so all can use it
+               $this->setDebugInstance($this);
+       }
+
+       /**
+        * Create a new debug output system.
+        * If no output is given this class is currently being used for back-fall.
+        * This fall-back mechanism will become deprecated very soon.
+        *
+        * @param       $outputClass    The class name which we shall use for
+        *                                                      registering the *real* debug output
+        * @param       $className              Class where a output should be created and
+        *                                                      configured for
+        * @return      $debugInstance  An instance of this middleware class
+        */
+       public static final function createDebugMiddleware ($outputClass, $className) {
+               //* DEBUG-DIE: */ die(__METHOD__.': outputClass=' . $outputClass . ',className=' . $className);
+
+               // Create an instance if this middleware
+               $debugInstance = new DebugMiddleware();
+
+               // Default is that $outputClass may be invalid
+               $isInitialized = FALSE;
+
+               // Is there a valid output instance provided?
+               if ((!is_null($outputClass)) && (is_object($outputClass)) && ($outputClass instanceof OutputStreamer)) {
+                       // Use the given output instance
+                       $debugInstance->setOutputInstance($outputClass);
+
+                       // All fine
+                       $isInitialized = TRUE;
+               } elseif ((!is_null($outputClass)) && (is_string($outputClass)) && (class_exists($outputClass))) {
+                       // A name for a debug output class has been provided so we try to get it
+                       $outputInstance = ObjectFactory::createObjectByName($outputClass);
+
+                       // Set this as output class
+                       $debugInstance->setOutputInstance($outputInstance);
+
+                       // All fine
+                       $isInitialized = TRUE;
+               }
+
+               // Is the output class initialized?
+               if ($isInitialized === TRUE) {
+                       // Then set class name
+                       $debugInstance->getOutputInstance()->setLoggerClassName($className);
+               } // END - if
+
+               // Return instance
+               return $debugInstance;
+       }
+
+       /**
+        * Getter for an instance of this class
+        *
+        * @return      $selfInstance           An instance of this class
+        */
+       public static final function getSelfInstance() {
+               return self::$selfInstance;
+       }
+
+       /**
+        * This method shall send debug output which can be HTML code for the
+        * browser or debug lines for a log file, etc. to the registered debug
+        * output instance.
+        *
+        * @param       $outStream      Data we shall 'stream' out to the world
+        * @param       $stripTags      Whether HTML tags shall be stripped out
+        * @return      void
+        */
+       public final function output ($outStream, $stripTags = FALSE) {
+               // Is the output stream set
+               if (empty($outStream)) {
+                       // @TODO Initialization phase
+                       return;
+               } // END - if
+
+               // Use the output instance
+               $this->getOutputInstance()->outputStream($outStream, $stripTags);
+       }
+}
+
+// [EOF]
+?>