From: Roland Haeder Date: Tue, 14 Jul 2015 21:20:40 +0000 (+0200) Subject: Continued with logger facility: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1d46c3751597719be1222c64cfccb051dbc149d4;p=core.git 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) Signed-off-by: Roland Häder --- 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/debug/.htaccess b/inc/classes/main/debug/.htaccess deleted file mode 100644 index 3a428827..00000000 --- a/inc/classes/main/debug/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/inc/classes/main/debug/class_DebugConsoleOutput.php b/inc/classes/main/debug/class_DebugConsoleOutput.php deleted file mode 100644 index 285c955d..00000000 --- a/inc/classes/main/debug/class_DebugConsoleOutput.php +++ /dev/null @@ -1,136 +0,0 @@ - - * @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 DebugConsoleOutput extends BaseFrameworkSystem implements Debugger, OutputStreamer, Registerable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @return $debugInstance The prepared debug instance - */ - public static final function createDebugConsoleOutput () { - // Get a new instance - $debugInstance = new DebugConsoleOutput(); - - // Return it - return $debugInstance; - } - - /** - * Outputs the given data without HTML tags - * - * @param $output The HTML'ed output - * @param $stripTags Whether HTML tags shall be stripped out - * @return void - */ - public final function outputStream ($output, $stripTags = FALSE) { - // Strip HTML tags out? - if ($stripTags === TRUE) { - // Prepare the output without HTML tags - $output = trim(html_entity_decode(strip_tags(stripslashes($output)))); - } else { - // Prepare the output with HTML tags - $output = trim(stripslashes($output)); - } - - // Are debug times enabled? - if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') { - // Output it first - $output = $this->getPrintableExecutionTime() . $output; - } // END - if - - // And print it out... - printf('%s%s', $output, chr(10)); - } - - /** - * Output the code - * - * @param $outStream Stream to output - * @param $stripTags Whether HTML tags shall be stripped out - * @return void - */ - public final function output ($outStream = FALSE, $stripTags = FALSE) { - // Empty output will be silently ignored - if ($outStream !== FALSE) { - $this->outputStream($outStream, $stripTags); - } // END - if - } - - /** - * Streams the data and maybe does something to it - * - * @param $data The data (string mostly) to "stream" - * @return $data The data (string mostly) to "stream" - * @throws UnsupportedOperationException If this method is called - */ - public function streamData ($data) { - self::createDebugInstance(__CLASS__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.'); - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * 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/debug/class_DebugErrorLogOutput.php b/inc/classes/main/debug/class_DebugErrorLogOutput.php deleted file mode 100644 index 74963830..00000000 --- a/inc/classes/main/debug/class_DebugErrorLogOutput.php +++ /dev/null @@ -1,133 +0,0 @@ - - * @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 DebugErrorLogOutput extends BaseFrameworkSystem implements Debugger, OutputStreamer { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @return $debugInstance The prepared debug instance - */ - public static final function createDebugErrorLogOutput () { - // Get a new instance - $debugInstance = new DebugErrorLogOutput(); - - // Return it - return $debugInstance; - } - - /** - * Outputs the given data without HTML tags, ignores $stripTags - * - * @param $output The HTML'ed output - * @param $stripTags Whether HTML tags shall be stripped out - * @return void - */ - public final function outputStream ($output, $stripTags = FALSE) { - // Split multiple lines into and array to put them out line-by-line - $errorLines = explode(chr(10), $output); - - // "Walk" through all lines - foreach ($errorLines as $err) { - // Trim any spaces, \n, \r etc. out - $err = trim($err); - - // Log only none-empty lines - if (!empty($err)) { - // Log this line - error_log(html_entity_decode(strip_tags($err)), 0); - } // END - if - } // END - foreach - } - - /** - * Output the code - * - * @param $outStream Stream to output - * @param $stripTags Whether HTML tags shall be stripped out - * @return void - */ - public final function output ($outStream = FALSE, $stripTags = FALSE) { - // Empty output will be silently ignored - if ($outStream !== FALSE) { - $this->outputStream($outStream); - } - } - - /** - * Streams the data and maybe does something to it - * - * @param $data The data (string mostly) to "stream" - * @return $data The data (string mostly) to "stream" - * @throws UnsupportedOperationException If this method is called - */ - public function streamData ($data) { - self::createDebugInstance(__CLASS__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.'); - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Determines for 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/debug/class_DebugWebOutput.php b/inc/classes/main/debug/class_DebugWebOutput.php deleted file mode 100644 index 0da9db7e..00000000 --- a/inc/classes/main/debug/class_DebugWebOutput.php +++ /dev/null @@ -1,122 +0,0 @@ - - * @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 DebugWebOutput extends BaseFrameworkSystem implements Debugger, OutputStreamer { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @return $debugInstance The prepared debug instance - */ - public static final function createDebugWebOutput () { - // Get a new instance - $debugInstance = new DebugWebOutput(); - - // Return it - return $debugInstance; - } - - /** - * Outputs the given data directly, ignores $stripTags - * - * @param $output The HTML output - * @param $stripTags Whether HTML tags shall be stripped out - * @return void - */ - public final function outputStream ($output, $stripTags = FALSE) { - // Strip out
- $output = str_replace('
', '', $output); - print(stripslashes($output)."
\n"); - } - - /** - * Output the code - * - * @param $outStream Stream to output - * @param $stripTags Whether HTML tags shall be stripped out - * @return void - */ - public final function output ($outStream = FALSE, $stripTags = FALSE) { - // Empty output will be silently ignored - if ($outStream !== FALSE) { - $this->outputStream($outStream, $stripTags); - } // END - if - } - - /** - * Streams the data and maybe does something to it - * - * @param $data The data (string mostly) to "stream" - * @return $data The data (string mostly) to "stream" - * @throws UnsupportedOperationException If this method is called - */ - public function streamData ($data) { - self::createDebugInstance(__CLASS__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.'); - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * 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_ 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/output/class_ConsoleOutput.php b/inc/classes/main/output/class_ConsoleOutput.php deleted file mode 100644 index e920c6ea..00000000 --- a/inc/classes/main/output/class_ConsoleOutput.php +++ /dev/null @@ -1,129 +0,0 @@ - - * @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 ConsoleOutput extends BaseFrameworkSystem implements OutputStreamer { - /** - * The instance for the singleton design pattern - */ - private static $consoleInstance = NULL; - - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Create a new web output system and set the content type - * - * @param $contentType A valid content-type - * @return $debugInstance An instance of this middleware class - */ - public static final function createConsoleOutput ($contentType) { - // Cast the content-type to string - $contentType = (string) $contentType; - $contentType = trim($contentType); - - // Get instance - self::$consoleInstance = new ConsoleOutput(); - - // Set the content type - // @TODO Need to rewrite this to $requestInstance->addHeader() - if (!empty($contentType)) { - @header(sprintf('Content-type: %s', - $contentType - )); - } // END - if - - // Return instance - return self::$consoleInstance; - } - - /** - * Getter for an instance of this class - * - * @return $consoleInstance An instance of this class - */ - public static final function getInstance() { - // Is the self-instance already set? - if (is_null(self::$consoleInstance)) { - $contentType = FrameworkConfiguration::getSelfInstance()->getConfigEntry('web_content_type'); - self::$consoleInstance = ConsoleOutput::createConsoleOutput($contentType); - } // END - if - - // Return the instance - return self::$consoleInstance; - } - - /** - * Output the code - * - * @param $outStream Something we shall sent to the console - * @param $stripTags Whether HTML tags shall be stripped out - * @return void - */ - public final function output ($outStream = FALSE, $stripTags = FALSE) { - print trim($outStream) . PHP_EOL; - } - - /** - * 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_WebOutput.php b/inc/classes/main/output/class_WebOutput.php deleted file mode 100644 index 58d2db0a..00000000 --- a/inc/classes/main/output/class_WebOutput.php +++ /dev/null @@ -1,113 +0,0 @@ - - * @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 WebOutput extends BaseFrameworkSystem implements OutputStreamer, Registerable { - /** - * The instance for the singleton design pattern - */ - private static $webInstance = NULL; - - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Create a new web 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::$webInstance)) { - // Get a new instance and set it - self::$webInstance = new WebOutput(); - - // Get the content type - $contentType = self::$webInstance->getConfigInstance()->getConfigEntry('web_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::$webInstance; - } - - /** - * Output the code - * - * @param $outStream Stream to output - * @param $stripTags Whether HTML tags shall be stripped out - * @return void - */ - public final function output ($outStream = FALSE, $stripTags = FALSE) { - print(stripslashes($outStream)); - } - - /** - * 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/console/.htaccess b/inc/classes/main/output/console/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/main/output/console/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/output/console/class_ConsoleOutput.php b/inc/classes/main/output/console/class_ConsoleOutput.php new file mode 100644 index 00000000..7d93422b --- /dev/null +++ b/inc/classes/main/output/console/class_ConsoleOutput.php @@ -0,0 +1,129 @@ + + * @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 ConsoleOutput extends BaseOutput implements OutputStreamer { + /** + * The instance for the singleton design pattern + */ + private static $consoleInstance = NULL; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Create a new web output system and set the content type + * + * @param $contentType A valid content-type + * @return $debugInstance An instance of this middleware class + */ + public static final function createConsoleOutput ($contentType) { + // Cast the content-type to string + $contentType = (string) $contentType; + $contentType = trim($contentType); + + // Get instance + self::$consoleInstance = new ConsoleOutput(); + + // Set the content type + // @TODO Need to rewrite this to $requestInstance->addHeader() + if (!empty($contentType)) { + @header(sprintf('Content-type: %s', + $contentType + )); + } // END - if + + // Return instance + return self::$consoleInstance; + } + + /** + * Getter for an instance of this class + * + * @return $consoleInstance An instance of this class + */ + public static final function getInstance() { + // Is the self-instance already set? + if (is_null(self::$consoleInstance)) { + $contentType = FrameworkConfiguration::getSelfInstance()->getConfigEntry('web_content_type'); + self::$consoleInstance = ConsoleOutput::createConsoleOutput($contentType); + } // END - if + + // Return the instance + return self::$consoleInstance; + } + + /** + * Output the code + * + * @param $outStream Something we shall sent to the console + * @param $stripTags Whether HTML tags shall be stripped out + * @return void + */ + public final function output ($outStream = FALSE, $stripTags = FALSE) { + print trim($outStream) . PHP_EOL; + } + + /** + * 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/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/output/debug/console/class_DebugConsoleOutput.php b/inc/classes/main/output/debug/console/class_DebugConsoleOutput.php new file mode 100644 index 00000000..d7591598 --- /dev/null +++ b/inc/classes/main/output/debug/console/class_DebugConsoleOutput.php @@ -0,0 +1,136 @@ + + * @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 DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStreamer, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $debugInstance The prepared debug instance + */ + public static final function createDebugConsoleOutput () { + // Get a new instance + $debugInstance = new DebugConsoleOutput(); + + // Return it + return $debugInstance; + } + + /** + * Outputs the given data without HTML tags + * + * @param $output The HTML'ed output + * @param $stripTags Whether HTML tags shall be stripped out + * @return void + */ + public final function outputStream ($output, $stripTags = FALSE) { + // Strip HTML tags out? + if ($stripTags === TRUE) { + // Prepare the output without HTML tags + $output = trim(html_entity_decode(strip_tags(stripslashes($output)))); + } else { + // Prepare the output with HTML tags + $output = trim(stripslashes($output)); + } + + // Are debug times enabled? + if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') { + // Output it first + $output = $this->getPrintableExecutionTime() . $output; + } // END - if + + // And print it out... + printf('%s%s', $output, chr(10)); + } + + /** + * Output the code + * + * @param $outStream Stream to output + * @param $stripTags Whether HTML tags shall be stripped out + * @return void + */ + public final function output ($outStream = FALSE, $stripTags = FALSE) { + // Empty output will be silently ignored + if ($outStream !== FALSE) { + $this->outputStream($outStream, $stripTags); + } // END - if + } + + /** + * Streams the data and maybe does something to it + * + * @param $data The data (string mostly) to "stream" + * @return $data The data (string mostly) to "stream" + * @throws UnsupportedOperationException If this method is called + */ + public function streamData ($data) { + self::createDebugInstance(__CLASS__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.'); + throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); + } + + /** + * 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/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/output/debug/error/class_DebugErrorLogOutput.php b/inc/classes/main/output/debug/error/class_DebugErrorLogOutput.php new file mode 100644 index 00000000..7124250c --- /dev/null +++ b/inc/classes/main/output/debug/error/class_DebugErrorLogOutput.php @@ -0,0 +1,133 @@ + + * @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 DebugErrorLogOutput extends BaseDebugOutput implements Debugger, OutputStreamer { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $debugInstance The prepared debug instance + */ + public static final function createDebugErrorLogOutput () { + // Get a new instance + $debugInstance = new DebugErrorLogOutput(); + + // Return it + return $debugInstance; + } + + /** + * Outputs the given data without HTML tags, ignores $stripTags + * + * @param $output The HTML'ed output + * @param $stripTags Whether HTML tags shall be stripped out + * @return void + */ + public final function outputStream ($output, $stripTags = FALSE) { + // Split multiple lines into and array to put them out line-by-line + $errorLines = explode(chr(10), $output); + + // "Walk" through all lines + foreach ($errorLines as $err) { + // Trim any spaces, \n, \r etc. out + $err = trim($err); + + // Log only none-empty lines + if (!empty($err)) { + // Log this line + error_log(html_entity_decode(strip_tags($err)), 0); + } // END - if + } // END - foreach + } + + /** + * Output the code + * + * @param $outStream Stream to output + * @param $stripTags Whether HTML tags shall be stripped out + * @return void + */ + public final function output ($outStream = FALSE, $stripTags = FALSE) { + // Empty output will be silently ignored + if ($outStream !== FALSE) { + $this->outputStream($outStream); + } + } + + /** + * Streams the data and maybe does something to it + * + * @param $data The data (string mostly) to "stream" + * @return $data The data (string mostly) to "stream" + * @throws UnsupportedOperationException If this method is called + */ + public function streamData ($data) { + self::createDebugInstance(__CLASS__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.'); + throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); + } + + /** + * Determines for 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/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/output/debug/web/class_DebugWebOutput.php b/inc/classes/main/output/debug/web/class_DebugWebOutput.php new file mode 100644 index 00000000..b8c34cb6 --- /dev/null +++ b/inc/classes/main/output/debug/web/class_DebugWebOutput.php @@ -0,0 +1,122 @@ + + * @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 DebugWebOutput extends BaseDebugOutput implements Debugger, OutputStreamer { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $debugInstance The prepared debug instance + */ + public static final function createDebugWebOutput () { + // Get a new instance + $debugInstance = new DebugWebOutput(); + + // Return it + return $debugInstance; + } + + /** + * Outputs the given data directly, ignores $stripTags + * + * @param $output The HTML output + * @param $stripTags Whether HTML tags shall be stripped out + * @return void + */ + public final function outputStream ($output, $stripTags = FALSE) { + // Strip out
+ $output = str_replace('
', '', $output); + print(stripslashes($output)."
\n"); + } + + /** + * Output the code + * + * @param $outStream Stream to output + * @param $stripTags Whether HTML tags shall be stripped out + * @return void + */ + public final function output ($outStream = FALSE, $stripTags = FALSE) { + // Empty output will be silently ignored + if ($outStream !== FALSE) { + $this->outputStream($outStream, $stripTags); + } // END - if + } + + /** + * Streams the data and maybe does something to it + * + * @param $data The data (string mostly) to "stream" + * @return $data The data (string mostly) to "stream" + * @throws UnsupportedOperationException If this method is called + */ + public function streamData ($data) { + self::createDebugInstance(__CLASS__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.'); + throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); + } + + /** + * 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/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/web/class_WebOutput.php b/inc/classes/main/output/web/class_WebOutput.php new file mode 100644 index 00000000..76f9be52 --- /dev/null +++ b/inc/classes/main/output/web/class_WebOutput.php @@ -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 WebOutput extends BaseOutput implements OutputStreamer, Registerable { + /** + * The instance for the singleton design pattern + */ + private static $webInstance = NULL; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Create a new web 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::$webInstance)) { + // Get a new instance and set it + self::$webInstance = new WebOutput(); + + // Get the content type + $contentType = self::$webInstance->getConfigInstance()->getConfigEntry('web_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::$webInstance; + } + + /** + * Output the code + * + * @param $outStream Stream to output + * @param $stripTags Whether HTML tags shall be stripped out + * @return void + */ + public final function output ($outStream = FALSE, $stripTags = FALSE) { + print(stripslashes($outStream)); + } + + /** + * 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/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; }