eval() commands replace by improved object factory, user login class stub added
[shipsimu.git] / inc / classes / middleware / debug / class_DebugMiddleware.php
index 2cc4882..5c1e050 100644 (file)
@@ -4,11 +4,11 @@
  * become registered with this middleware because the back-fall class will
  * become deprecated soon.
  *
- * @author             Roland Haeder <webmaster@mxchange.org>
- * @version            0.3.0
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
  * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.mxchange.org
+ * @link               http://www.ship-simu.org
  *
  * 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
@@ -27,7 +27,7 @@ class DebugMiddleware extends BaseMiddleware {
        /**
         * The concrete output instance
         */
-       private $outputHandler = null;
+       private $outputInstance = null;
 
        /**
         * An instance of this class
@@ -35,19 +35,19 @@ class DebugMiddleware extends BaseMiddleware {
        private static $thisInstance = null;
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
-       private final function __construct () {
+       protected function __construct () {
                // Call parent constructor
-               parent::constructor(__CLASS__);
+               parent::__construct(__CLASS__);
 
                // Set description
-               $this->setObjectDescription("Debug-Ausgabe-Handler");
+               $this->setObjectDescription("Debug-Ausgabe-Instance");
 
                // Create an unique ID
-               $this->createUniqueID();
+               $this->generateUniqueId();
 
                // Set own instance
                self::$thisInstance = $this;
@@ -58,36 +58,24 @@ class DebugMiddleware extends BaseMiddleware {
         * If no output is given this class is currently being used for back-fall.
         * This fall-back mechanism will become deprecated very soon.
         *
-        * @param               $debuggerClass       The class name which we shall use for
+        * @param       $debuggerClass  The class name which we shall use for
         *                                                      registering the *real* debug output
-        * @return      $debugInstance          An instance of this middleware class
+        * @return      $debugInstance  An instance of this middleware class
         */
        public final static function createDebugMiddleware ($debuggerClass) {
                // Create an instance if this middleware
                $debugInstance = new DebugMiddleware();
 
-               // Is there a valid output handler provided?
-               if ((!is_null($debuggerClass)) && (is_object($debuggerClass)) && (method_exists($debuggerClass, 'outputStream'))) {
-                       // Use the given output system
-                       $debugInstance->setOutputHandler($debuggerClass);
+               // Is there a valid output instance provided?
+               if ((!is_null($debuggerClass)) && (is_object($debuggerClass)) && ($debuggerClass instanceof OutputStreamer)) {
+                       // Use the given output instance
+                       $debugInstance->setOutputInstance($debuggerClass);
                } elseif ((!is_null($debuggerClass)) && (is_string($debuggerClass)) && (class_exists($debuggerClass))) {
                        // A name for a debug output class has been provided so we try to get it
-                       $eval = sprintf("\$debuggerClass = %s::create%s();",
-                               $debuggerClass,
-                               $debuggerClass
-                       );
+                       $debuggerInstance = ObjectFactory::createObjectByName($debuggerClass);
 
-                       // Run the constructed name
-                       @eval($eval);
-
-                       // Was this successfull?
-                       if ((is_object($debuggerClass)) && (method_exists($debuggerClass, "outputStream"))) {
-                               // Set this as output class
-                               $debugInstance->setOutputHandler($debuggerClass);
-                       } else {
-                               // No object or method is missing use fall-back
-                               throw new MissingMethodException(array($debuggerClass, 'outputStream'), self::EXCEPTION_MISSING_METHOD);
-                       }
+                       // Set this as output class
+                       $debugInstance->setOutputInstance($debuggerInstance);
                }
 
                // Return instance
@@ -104,32 +92,33 @@ class DebugMiddleware extends BaseMiddleware {
        }
 
        /**
-        * Setter for output handler
+        * Setter for output instance
         *
+        * @param       $outputInstance The debug output instance
         * @return      void
         */
-       public final function setOutputHandler ($outputHandler) {
-               $this->outputHandler = $outputHandler;
+       public final function setOutputInstance (OutputStreamer $outputInstance) {
+               $this->outputInstance = $outputInstance;
        }
 
        /**
         * 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 handler.
+        * output instance.
         *
         * @return      void
         */
        public final function output ($outStream) {
-               // Check if the output handler is valid
-               if (is_null($this->outputHandler)) {
-                       // Debug output handler was not set
+               // Check if the output instance is valid
+               if (is_null($this->outputInstance)) {
+                       // Debug output instance was not set
                        throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
-               } elseif (!is_object($this->outputHandler)) {
-                       // The debug output handler is not an object
-                       throw new NoObjectException($this->ouputHandler, self::EXCEPTION_IS_NO_OBJECT);
-               } elseif (!method_exists($this->outputHandler, 'outputStream')) {
+               } elseif (!is_object($this->outputInstance)) {
+                       // The debug output instance is not an object
+                       throw new NoObjectException($this->ouputInstance, self::EXCEPTION_IS_NO_OBJECT);
+               } elseif (!method_exists($this->outputInstance, 'outputStream')) {
                        // The required method outputStream() is missing
-                       throw new MissingMethodException(array($this->outputHandler, 'outputStream'), self::EXCEPTION_MISSING_METHOD);
+                       throw new MissingMethodException(array($this->outputInstance, 'outputStream'), self::EXCEPTION_MISSING_METHOD);
                }
 
                // Is the output stream set
@@ -138,8 +127,8 @@ class DebugMiddleware extends BaseMiddleware {
                        return;
                }
 
-               // Use the output handler
-               $this->outputHandler->outputStream($outStream);
+               // Use the output instance
+               $this->outputInstance->outputStream($outStream);
        }
 }