From 5a6b52f93d9167cc289ae0678aecc5d31ec0435c Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Sat, 9 Feb 2019 20:25:49 +0100 Subject: [PATCH] Implemented changes requested by WebComponent --- src/FuzeWorks/Configurator.php | 18 ++++++++++++++++-- src/FuzeWorks/Core.php | 8 -------- src/FuzeWorks/Logger.php | 11 ++++++----- src/FuzeWorks/Plugins.php | 2 +- src/Layout/layout.logger_http.php | 4 ++++ test/core/abstract.coreTestAbstract.php | 3 --- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/FuzeWorks/Configurator.php b/src/FuzeWorks/Configurator.php index f1dd8e4..956c2a4 100644 --- a/src/FuzeWorks/Configurator.php +++ b/src/FuzeWorks/Configurator.php @@ -151,9 +151,11 @@ class Configurator */ public function addComponent(iComponent $component): Configurator { - $this->components[] = $component; - $component->onAddComponent($this); + if (in_array($component, $this->components)) + return $this; + $component->onAddComponent($this); + $this->components[] = $component; return $this; } @@ -212,6 +214,18 @@ class Configurator return $this; } + /** + * Set the template that FuzeWorks should use to parse debug logs + * + * @codeCoverageIgnore + * + * @var string Name of the template file + */ + public static function setLoggerTemplate($templateName) + { + Logger::setLoggerTemplate($templateName); + } + /** * Sets the default timezone. * @param string $timezone diff --git a/src/FuzeWorks/Core.php b/src/FuzeWorks/Core.php index 35116e7..097bc99 100644 --- a/src/FuzeWorks/Core.php +++ b/src/FuzeWorks/Core.php @@ -43,7 +43,6 @@ use FuzeWorks\Exception\EventException; * * Holds all the modules and starts the framework. Allows for starting and managing modules * - * @todo Test directory priorities in separate components * @author TechFuze * @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net) */ @@ -71,13 +70,6 @@ class Core public static $logDir; - /** - * The HTTP status code of the current request - * - * @var int $http_status_code Status code - */ - public static $http_status_code = 200; - /** * Initializes the core. * diff --git a/src/FuzeWorks/Logger.php b/src/FuzeWorks/Logger.php index 1cf6382..36a6c17 100644 --- a/src/FuzeWorks/Logger.php +++ b/src/FuzeWorks/Logger.php @@ -129,7 +129,6 @@ class Logger { // Set the environment variables self::$log_last_request = $cfg_error->get('log_last_request_to_file'); self::$log_errors_to_file = $cfg_error->get('log_errors_to_file'); - self::$logger_template = $cfg_error->get('logger_template'); self::newLevel('Logger Initiated'); } @@ -262,8 +261,9 @@ class Logger { * Please note that most of the user-defined exceptions will be caught in the router, and handled with the error-controller. * * @param Exception $exception The occured exception. + * @param bool $haltExecution. Defaults to true */ - public static function exceptionHandler($exception) + public static function exceptionHandler($exception, bool $haltExecution = true) { $LOG = array('type' => 'EXCEPTION', 'message' => $exception->getMessage(), @@ -274,7 +274,8 @@ class Logger { self::$logs[] = $LOG; // And return a 500 because this error was fatal - self::haltExecution($LOG); + if ($haltExecution) + self::haltExecution($LOG); } /** @@ -573,9 +574,9 @@ class Logger { * * Used for debugging timings in FuzeWorks * - * @return int Time passed since FuzeWorks init + * @return float Time passed since FuzeWorks init */ - private static function getRelativeTime(): int + private static function getRelativeTime(): float { $startTime = STARTTIME; $time = microtime(true) - $startTime; diff --git a/src/FuzeWorks/Plugins.php b/src/FuzeWorks/Plugins.php index 0bb5dd1..d75bdcd 100644 --- a/src/FuzeWorks/Plugins.php +++ b/src/FuzeWorks/Plugins.php @@ -133,7 +133,7 @@ class Plugins // If a header file exists, use it $file = $pluginPath . DS . $pluginFolder . DS . 'header.php'; $pluginFolder = ucfirst($pluginFolder); - $className = '\FuzeWorks\Plugins\\'.$pluginFolder.'Header'; + $className = '\Application\Plugin\\'.$pluginFolder.'Header'; if (file_exists($file)) { // Load the header file diff --git a/src/Layout/layout.logger_http.php b/src/Layout/layout.logger_http.php index 960b648..38dea88 100644 --- a/src/Layout/layout.logger_http.php +++ b/src/Layout/layout.logger_http.php @@ -44,6 +44,10 @@ foreach ($logs as $log) { } elseif ($log['type'] == 'LEVEL_STOP') { --$layer; $string .= ''; + } elseif ($log['type'] == 'EXCEPTION') { + $string .= '
[' . $log['type'] . '] ' . $log['message'] . ' + ' . (!empty($log['logFile']) ? $log['logFile'] : '') . ' : ' . (!empty($log['logLine']) ? $log['logLine'] : '') . '(' . round($log['runtime'] * 1000, 4) . ' ms)
'; + $string .= '
' . (!empty($log['context']) && is_string($log['context']) ? '[' . $log['context'] . ']' : '') . '
'; } elseif ($log['type'] == 'ERROR') { $string .= '
[' . $log['type'] . ']' . (!empty($log['context']) && is_string($log['context']) ? '[' . $log['context'] . ']' : '') . ' ' . $log['message'] . ' ' . (!empty($log['logFile']) ? $log['logFile'] : '') . ' : ' . (!empty($log['logLine']) ? $log['logLine'] : '') . '(' . round($log['runtime'] * 1000, 4) . ' ms)
'; diff --git a/test/core/abstract.coreTestAbstract.php b/test/core/abstract.coreTestAbstract.php index ef4859a..3cd45d2 100644 --- a/test/core/abstract.coreTestAbstract.php +++ b/test/core/abstract.coreTestAbstract.php @@ -63,9 +63,6 @@ abstract class CoreTestAbstract extends TestCase // Re-enable events, in case they have been disabled Events::enable(); - // Reset the HTTP status code - Core::$http_status_code = 200; - // Remove Config overrides Config::$configOverrides = []; }