From 1d46c3751597719be1222c64cfccb051dbc149d4 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 14 Jul 2015 23:20:40 +0200 Subject: [PATCH] Continued with logger facility: - Introduced BaseOutput and BaseDebugOutput - Moved debug/ classes to outut/debug// as can be console, error and web (later for HTML/HTTP output; careful, this may break sending HTTP headers!) - Handled over the class' name the logger is being created for (for later configuration with XMLs) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../main/class_BaseFrameworkSystem.php | 2 +- inc/classes/main/output/class_ | 113 ++++++++++++++++++ inc/classes/main/output/class_BaseOutput.php | 38 ++++++ .../main/{debug => output/console}/.htaccess | 0 .../{ => console}/class_ConsoleOutput.php | 2 +- inc/classes/main/output/debug/.htaccess | 1 + .../main/output/debug/console/.htaccess | 1 + .../console}/class_DebugConsoleOutput.php | 2 +- inc/classes/main/output/debug/error/.htaccess | 1 + .../error}/class_DebugErrorLogOutput.php | 2 +- inc/classes/main/output/debug/web/.htaccess | 1 + .../debug/web}/class_DebugWebOutput.php | 2 +- inc/classes/main/output/log_file/.htaccess | 1 + inc/classes/main/output/web/.htaccess | 1 + .../main/output/{ => web}/class_WebOutput.php | 2 +- .../debug/class_DebugMiddleware.php | 32 +++-- 16 files changed, 188 insertions(+), 13 deletions(-) create mode 100644 inc/classes/main/output/class_ create mode 100644 inc/classes/main/output/class_BaseOutput.php rename inc/classes/main/{debug => output/console}/.htaccess (100%) rename inc/classes/main/output/{ => console}/class_ConsoleOutput.php (98%) create mode 100644 inc/classes/main/output/debug/.htaccess create mode 100644 inc/classes/main/output/debug/console/.htaccess rename inc/classes/main/{debug => output/debug/console}/class_DebugConsoleOutput.php (97%) create mode 100644 inc/classes/main/output/debug/error/.htaccess rename inc/classes/main/{debug => output/debug/error}/class_DebugErrorLogOutput.php (97%) create mode 100644 inc/classes/main/output/debug/web/.htaccess rename inc/classes/main/{debug => output/debug/web}/class_DebugWebOutput.php (97%) create mode 100644 inc/classes/main/output/log_file/.htaccess create mode 100644 inc/classes/main/output/web/.htaccess rename inc/classes/main/output/{ => web}/class_WebOutput.php (97%) diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 6fa9f3ad..26986067 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -1857,7 +1857,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Try it try { // Get a debugger instance - $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_' . self::getResponseTypeFromSystem() . '_class')); + $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_' . self::getResponseTypeFromSystem() . '_class'), $className); } catch (NullPointerException $e) { // Didn't work, no instance there exit('Cannot create debugInstance! Exception=' . $e->__toString() . ', message=' . $e->getMessage()); diff --git a/inc/classes/main/output/class_ b/inc/classes/main/output/class_ new file mode 100644 index 00000000..01161ac5 --- /dev/null +++ b/inc/classes/main/output/class_ @@ -0,0 +1,113 @@ + + * @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 + * + * 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 . + */ +class ???Output extends BaseOutput implements OutputStreamer, Registerable { + /** + * The instance for the singleton design pattern + */ + private static $!!!Instance = NULL; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Create a new !!! output system and set the content type + * + * @param $applicationInstance An instance of a ManageableApplication class + * @return $debugInstance An instance of this middleware class + */ + public static final function createWebOutput (ManageableApplication $applicationInstance) { + // Is the self-instance already set? + if (is_null(self::$!!!Instance)) { + // Get a new instance and set it + self::$!!!Instance = new WebOutput(); + + // Get the content type + $contentType = self::$!!!Instance->getConfigInstance()->getConfigEntry('!!!_content_type'); + + // Set the content type + if (!empty($contentType)) { + // Set the header + $applicationInstance->getResponseInstance()->addHeader('Content-type', $contentType); + } // END - if + } // END - if + + // Return instance + return self::$!!!Instance; + } + + /** + * Output the code + * + * @param $outStream Stream to output + * @param $stripTags Whether HTML tags shall be stripped out + * @return void + * @todo 0% done + */ + public final function output ($outStream = FALSE, $stripTags = FALSE) { + $this->partialStub('Please implement this method. outStream()=' . strlen($outStream) . ',stripTags=' . intval($stripTags)); + } + + /** + * Determines seek position + * + * @return $seekPosition Current seek position + * @throws UnsupportedOperationException If this method is called + */ + public function determineSeekPosition () { + throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); + } + + /** + * Seek to given offset (default) or other possibilities as fseek() gives. + * + * @param $offset Offset to seek to (or used as "base" for other seeks) + * @param $whence Added to offset (default: only use offset to seek to) + * @return $status Status of file seek: 0 = success, -1 = failed + * @throws UnsupportedOperationException If this method is called + */ + public function seek ($offset, $whence = SEEK_SET) { + self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] offset=' . $offset . ',whence=' . $whence); + throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); + } + + /** + * Size of file stack + * + * @return $size Size (in bytes) of file + * @throws UnsupportedOperationException If this method is called + */ + public function size () { + throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/output/class_BaseOutput.php b/inc/classes/main/output/class_BaseOutput.php new file mode 100644 index 00000000..484db423 --- /dev/null +++ b/inc/classes/main/output/class_BaseOutput.php @@ -0,0 +1,38 @@ + + * @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 + * + * 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 . + */ +class BaseOutput extends BaseFrameworkSystem { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/debug/.htaccess b/inc/classes/main/output/console/.htaccess similarity index 100% rename from inc/classes/main/debug/.htaccess rename to inc/classes/main/output/console/.htaccess diff --git a/inc/classes/main/output/class_ConsoleOutput.php b/inc/classes/main/output/console/class_ConsoleOutput.php similarity index 98% rename from inc/classes/main/output/class_ConsoleOutput.php rename to inc/classes/main/output/console/class_ConsoleOutput.php index e920c6ea..7d93422b 100644 --- a/inc/classes/main/output/class_ConsoleOutput.php +++ b/inc/classes/main/output/console/class_ConsoleOutput.php @@ -22,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class ConsoleOutput extends BaseFrameworkSystem implements OutputStreamer { +class ConsoleOutput extends BaseOutput implements OutputStreamer { /** * The instance for the singleton design pattern */ diff --git a/inc/classes/main/output/debug/.htaccess b/inc/classes/main/output/debug/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/main/output/debug/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/output/debug/console/.htaccess b/inc/classes/main/output/debug/console/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/main/output/debug/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/debug/class_DebugConsoleOutput.php b/inc/classes/main/output/debug/console/class_DebugConsoleOutput.php similarity index 97% rename from inc/classes/main/debug/class_DebugConsoleOutput.php rename to inc/classes/main/output/debug/console/class_DebugConsoleOutput.php index 285c955d..d7591598 100644 --- a/inc/classes/main/debug/class_DebugConsoleOutput.php +++ b/inc/classes/main/output/debug/console/class_DebugConsoleOutput.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class DebugConsoleOutput extends BaseFrameworkSystem implements Debugger, OutputStreamer, Registerable { +class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStreamer, Registerable { /** * Protected constructor * diff --git a/inc/classes/main/output/debug/error/.htaccess b/inc/classes/main/output/debug/error/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/main/output/debug/error/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/debug/class_DebugErrorLogOutput.php b/inc/classes/main/output/debug/error/class_DebugErrorLogOutput.php similarity index 97% rename from inc/classes/main/debug/class_DebugErrorLogOutput.php rename to inc/classes/main/output/debug/error/class_DebugErrorLogOutput.php index 74963830..7124250c 100644 --- a/inc/classes/main/debug/class_DebugErrorLogOutput.php +++ b/inc/classes/main/output/debug/error/class_DebugErrorLogOutput.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class DebugErrorLogOutput extends BaseFrameworkSystem implements Debugger, OutputStreamer { +class DebugErrorLogOutput extends BaseDebugOutput implements Debugger, OutputStreamer { /** * Protected constructor * diff --git a/inc/classes/main/output/debug/web/.htaccess b/inc/classes/main/output/debug/web/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/main/output/debug/web/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/debug/class_DebugWebOutput.php b/inc/classes/main/output/debug/web/class_DebugWebOutput.php similarity index 97% rename from inc/classes/main/debug/class_DebugWebOutput.php rename to inc/classes/main/output/debug/web/class_DebugWebOutput.php index 0da9db7e..b8c34cb6 100644 --- a/inc/classes/main/debug/class_DebugWebOutput.php +++ b/inc/classes/main/output/debug/web/class_DebugWebOutput.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class DebugWebOutput extends BaseFrameworkSystem implements Debugger, OutputStreamer { +class DebugWebOutput extends BaseDebugOutput implements Debugger, OutputStreamer { /** * Protected constructor * diff --git a/inc/classes/main/output/log_file/.htaccess b/inc/classes/main/output/log_file/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/main/output/log_file/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/output/web/.htaccess b/inc/classes/main/output/web/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/main/output/web/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/output/class_WebOutput.php b/inc/classes/main/output/web/class_WebOutput.php similarity index 97% rename from inc/classes/main/output/class_WebOutput.php rename to inc/classes/main/output/web/class_WebOutput.php index 58d2db0a..76f9be52 100644 --- a/inc/classes/main/output/class_WebOutput.php +++ b/inc/classes/main/output/web/class_WebOutput.php @@ -22,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class WebOutput extends BaseFrameworkSystem implements OutputStreamer, Registerable { +class WebOutput extends BaseOutput implements OutputStreamer, Registerable { /** * The instance for the singleton design pattern */ diff --git a/inc/classes/middleware/debug/class_DebugMiddleware.php b/inc/classes/middleware/debug/class_DebugMiddleware.php index 328281b6..1f6c6b35 100644 --- a/inc/classes/middleware/debug/class_DebugMiddleware.php +++ b/inc/classes/middleware/debug/class_DebugMiddleware.php @@ -55,26 +55,44 @@ class DebugMiddleware extends BaseMiddleware implements Registerable { * 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 $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 ($debuggerClass) { + public static final function createDebugMiddleware ($outputClass, $className) { + 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($debuggerClass)) && (is_object($debuggerClass)) && ($debuggerClass instanceof OutputStreamer)) { + if ((!is_null($outputClass)) && (is_object($outputClass)) && ($outputClass instanceof OutputStreamer)) { // Use the given output instance - $debugInstance->setOutputInstance($debuggerClass); - } elseif ((!is_null($debuggerClass)) && (is_string($debuggerClass)) && (class_exists($debuggerClass))) { + $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 - $debuggerInstance = ObjectFactory::createObjectByName($debuggerClass); + $outputInstance = ObjectFactory::createObjectByName($outputClass); // Set this as output class - $debugInstance->setOutputInstance($debuggerInstance); + $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; } -- 2.39.5