Implemented multiple requests. Mostly rewritten the Logger to be more compatible with Plugins and Components.
This commit is contained in:
parent
961a4c4081
commit
3154718f94
|
@ -18,8 +18,7 @@
|
|||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7",
|
||||
"mikey179/vfsStream": "1.1.*",
|
||||
"tracy/tracy": "2.4.*"
|
||||
"mikey179/vfsStream": "1.1.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
|
@ -39,5 +39,5 @@ return array(
|
|||
'php_error_reporting' => false,
|
||||
'log_errors_to_file' => true,
|
||||
'log_last_request_to_file' => false,
|
||||
'logger_template' => 'logger_default',
|
||||
'logger_template' => 'logger_cli',
|
||||
);
|
|
@ -38,6 +38,7 @@ namespace FuzeWorks;
|
|||
use FuzeWorks\ConfigORM\ConfigORM;
|
||||
use FuzeWorks\Event\ConfigGetEvent;
|
||||
use FuzeWorks\Exception\ConfigException;
|
||||
use FuzeWorks\Exception\EventException;
|
||||
|
||||
/**
|
||||
* Config Class.
|
||||
|
@ -148,7 +149,7 @@ class Config
|
|||
try {
|
||||
$event = Events::fireEvent('configGetEvent', $configName, $configPaths);
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Exception\EventException $e) {
|
||||
} catch (EventException $e) {
|
||||
throw new ConfigException("Could not load config. ConfigGetEvent fired exception: '" . $e->getMessage() . "''", 1);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
@ -178,7 +179,6 @@ class Config
|
|||
|
||||
// Return object
|
||||
return $configORM;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,17 @@ class Config
|
|||
if (file_exists($file))
|
||||
{
|
||||
// Load object
|
||||
return (new ConfigORM())->load($file);
|
||||
$configORM = (new ConfigORM())->load($file);
|
||||
|
||||
// Override config values if they exist
|
||||
if (isset(self::$configOverrides[$event->configName]))
|
||||
{
|
||||
foreach (self::$configOverrides[$event->configName] as $configKey => $configValue)
|
||||
$configORM->{$configKey} = $configValue;
|
||||
}
|
||||
|
||||
// Return object
|
||||
return $configORM;
|
||||
}
|
||||
|
||||
throw new ConfigException("Could not load config. File $event->configName not found", 1);
|
||||
|
|
|
@ -196,8 +196,10 @@ class Configurator
|
|||
*/
|
||||
public function setTimeZone(string $timezone): Configurator
|
||||
{
|
||||
if (!date_default_timezone_set($timezone))
|
||||
if (!in_array($timezone, timezone_identifiers_list()))
|
||||
throw new InvalidArgumentException("Could not set timezone. Invalid timezone provided.", 1);
|
||||
|
||||
@date_default_timezone_set($timezone);
|
||||
@ini_set('date.timezone', $timezone); // @ - function may be disabled
|
||||
|
||||
return $this;
|
||||
|
@ -221,12 +223,12 @@ class Configurator
|
|||
|
||||
/**
|
||||
* Fully enable or disable debug mode using one variable
|
||||
* @param bool $bool
|
||||
* @return Configurator
|
||||
*/
|
||||
public function enableDebugMode(bool $bool = true): Configurator
|
||||
public function enableDebugMode(): Configurator
|
||||
{
|
||||
$this->parameters['debugEnabled'] = $bool;
|
||||
$this->parameters['debugEnabled'] = true;
|
||||
$this->parameters['debugMatch'] = (isset($this->parameters['debugMatch']) ? $this->parameters['debugMatch'] : false);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -257,7 +259,7 @@ class Configurator
|
|||
return $this;
|
||||
}
|
||||
|
||||
// Otherwise we run the regular tracy detectDebugMode
|
||||
// Otherwise we run the regular detectDebugMode from Tracy
|
||||
$list = is_string($address)
|
||||
? preg_split('#[,\s]+#', $address)
|
||||
: (array) $address;
|
||||
|
@ -277,18 +279,6 @@ class Configurator
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the email to send logs to from Tracy
|
||||
* @param string
|
||||
* @return Configurator
|
||||
*/
|
||||
public function setDebugEmail($email): Configurator
|
||||
{
|
||||
$this->parameters['debugEmail'] = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -315,22 +305,11 @@ class Configurator
|
|||
|
||||
// Then prepare the debugger
|
||||
$debug = ($this->parameters['debugEnabled'] && $this->parameters['debugMatch'] ? true : false);
|
||||
if (!defined('ENVIRONMENT'))
|
||||
define('ENVIRONMENT', ($debug ? 'DEVELOPMENT' : 'PRODUCTION')); // @codeCoverageIgnore
|
||||
|
||||
// And enable Tracy Debugger
|
||||
if (class_exists('Tracy\Debugger', true))
|
||||
{
|
||||
Debugger::enable(!$debug, realpath($this->parameters['logDir']));
|
||||
if (isset($this->parameters['debugEmail']))
|
||||
{
|
||||
Debugger::$email = $this->parameters['debugEmail'];
|
||||
}
|
||||
Logger::$useTracy = true;
|
||||
}
|
||||
|
||||
// Then load the framework
|
||||
$container = Core::init();
|
||||
if ($debug == true)
|
||||
Logger::enable();
|
||||
|
||||
// Invoke deferredComponentClass on FuzeWorks\Core classes
|
||||
foreach ($this->deferredComponentClassMethods as $componentClass => $deferredComponentClasses)
|
||||
|
@ -341,9 +320,8 @@ class Configurator
|
|||
// @codeCoverageIgnoreStart
|
||||
foreach ($deferredComponentClasses as $deferredComponentClass)
|
||||
{
|
||||
|
||||
$deferredComponentClass->invoke(call_user_func_array(
|
||||
array($container->{$deferredComponentClass->componentClass}),
|
||||
array($container->{$deferredComponentClass->componentClass}, $deferredComponentClass->method),
|
||||
$deferredComponentClass->arguments
|
||||
));
|
||||
}
|
||||
|
@ -382,7 +360,7 @@ class Configurator
|
|||
}
|
||||
}
|
||||
|
||||
$component->onCreateContainer($this);
|
||||
$component->onCreateContainer($container);
|
||||
}
|
||||
|
||||
// And add all directories to the components
|
||||
|
|
|
@ -151,32 +151,6 @@ class Core
|
|||
return (PHP_SAPI === 'cli' OR defined('STDIN'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is HTTPS?
|
||||
*
|
||||
* Determines if the application is accessed via an encrypted
|
||||
* (HTTPS) connection.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isHttps(): bool
|
||||
{
|
||||
if ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off')
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
elseif ( ! empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off')
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for file writability
|
||||
*
|
||||
|
@ -220,95 +194,4 @@ class Core
|
|||
fclose($fp);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set HTTP Status Header
|
||||
*
|
||||
* @param int the status code
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
public static function setStatusHeader($code = 200, $text = '')
|
||||
{
|
||||
if (self::isCli())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($code) OR ! is_numeric($code))
|
||||
{
|
||||
throw new Exception('Status codes must be numeric', 1);
|
||||
}
|
||||
|
||||
if (empty($text))
|
||||
{
|
||||
is_int($code) OR $code = (int) $code;
|
||||
$stati = array(
|
||||
100 => 'Continue',
|
||||
101 => 'Switching Protocols',
|
||||
|
||||
200 => 'OK',
|
||||
201 => 'Created',
|
||||
202 => 'Accepted',
|
||||
203 => 'Non-Authoritative Information',
|
||||
204 => 'No Content',
|
||||
205 => 'Reset Content',
|
||||
206 => 'Partial Content',
|
||||
|
||||
300 => 'Multiple Choices',
|
||||
301 => 'Moved Permanently',
|
||||
302 => 'Found',
|
||||
303 => 'See Other',
|
||||
304 => 'Not Modified',
|
||||
305 => 'Use Proxy',
|
||||
307 => 'Temporary Redirect',
|
||||
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Timeout',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
422 => 'Unprocessable Entity',
|
||||
|
||||
500 => 'Internal Server Error',
|
||||
501 => 'Not Implemented',
|
||||
502 => 'Bad Gateway',
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Timeout',
|
||||
505 => 'HTTP Version Not Supported'
|
||||
);
|
||||
|
||||
if (isset($stati[$code]))
|
||||
{
|
||||
$text = $stati[$code];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CoreException('No status text available. Please check your status code number or supply your own message text.', 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos(PHP_SAPI, 'cgi') === 0)
|
||||
{
|
||||
header('Status: '.$code.' '.$text, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
$server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
|
||||
header($server_protocol.' '.$code.' '.$text, TRUE, $code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,10 +33,33 @@
|
|||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
?>
|
||||
<span title="Logger">
|
||||
<svg viewBox="0 0 2048 2048">
|
||||
<path d="M1792 1344v128q0 26-19 45t-45 19h-1664q-26 0-45-19t-19-45v-128q0-26 19-45t45-19h1664q26 0 45 19t19 45zm0-384v128q0 26-19 45t-45 19h-1664q-26 0-45-19t-19-45v-128q0-26 19-45t45-19h1664q26 0 45 19t19 45zm0-384v128q0 26-19 45t-45 19h-1664q-26 0-45-19t-19-45v-128q0-26 19-45t45-19h1664q26 0 45 19t19 45zm0-384v128q0 26-19 45t-45 19h-1664q-26 0-45-19t-19-45v-128q0-26 19-45t45-19h1664q26 0 45 19t19 45z" fill-opacity=".9" fill="#BDE797"/>
|
||||
</svg>
|
||||
<span class="tracy-label">Logger</span>
|
||||
</span>
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets loaded when a FuzeWorks execution is halted.
|
||||
*
|
||||
* Use this to change the output when execution is halted
|
||||
*
|
||||
* @author TechFuze <contact@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
*/
|
||||
class HaltExecutionEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @var array Log
|
||||
*/
|
||||
public $log;
|
||||
|
||||
public function init(array $log)
|
||||
{
|
||||
$this->log = $log;
|
||||
}
|
||||
|
||||
public function getLog(): array
|
||||
{
|
||||
return $this->log;
|
||||
}
|
||||
}
|
|
@ -157,7 +157,7 @@ class Factory
|
|||
try {
|
||||
$cfg = $this->config->get('core');
|
||||
} catch (ConfigException $e) {
|
||||
throw new CoreException("Could not initiate Factory. Config 'core 'could not be found.");
|
||||
throw new CoreException("Could not initiate Factory. Config 'core' could not be found.");
|
||||
}
|
||||
|
||||
// Disable events if requested to do so
|
||||
|
|
|
@ -1,259 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework Core.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.0.3
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
use Tracy\IBarPanel;
|
||||
use Tracy\Debugger;
|
||||
|
||||
/**
|
||||
* GitTracyBridge Class.
|
||||
*
|
||||
* This class provides adds a panel to the Tracy Bar showing the current git branch
|
||||
*
|
||||
* This class registers in Tracy, and creates a Bar object which contains the Git version.
|
||||
* @author Copyright (c) 2015 Jakub Vyvážil
|
||||
*/
|
||||
class GitTracyBridge implements IBarPanel {
|
||||
|
||||
/**
|
||||
* Register the bar
|
||||
*/
|
||||
public static function register()
|
||||
{
|
||||
$class = new self();
|
||||
$bar = Debugger::getBar();
|
||||
$bar->addPanel($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders HTML code for custom tab.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTab(): string
|
||||
{
|
||||
$style = '';
|
||||
if ($this->getBranchName() === 'master' || $this->getBranchName() === 'staging') {
|
||||
$style = 'background:#dd4742;color:white;padding:3px 4px 4px';
|
||||
}
|
||||
$icon = '<svg viewBox="10 10 512 512"><path fill="#f03c2e" d="M 502.34111,278.80364 278.79809,502.34216 c -12.86794,12.87712 -33.74784,12.87712 -46.63305,0 l -46.4152,-46.42448 58.88028,-58.88364 c 13.68647,4.62092 29.3794,1.51948 40.28378,-9.38732 10.97012,-10.9748 14.04307,-26.80288 9.30465,-40.537 l 56.75401,-56.74844 c 13.73383,4.73404 29.56829,1.67384 40.53842,-9.31156 15.32297,-15.3188 15.32297,-40.15196 0,-55.48356 -15.3341,-15.3322 -40.16175,-15.3322 -55.50254,0 -11.52454,11.53592 -14.37572,28.47172 -8.53182,42.6722 l -52.93386,52.93048 0,-139.28512 c 3.73267,-1.84996 7.25863,-4.31392 10.37114,-7.41756 15.32295,-15.3216 15.32295,-40.15196 0,-55.49696 -15.32296,-15.3166 -40.16844,-15.3166 -55.48025,0 -15.32296,15.345 -15.32296,40.17536 0,55.49696 3.78727,3.78288 8.17299,6.64472 12.85234,8.5604 l 0,140.57336 c -4.67935,1.91568 -9.05448,4.75356 -12.85234,8.56264 -11.60533,11.60168 -14.39801,28.6378 -8.4449,42.89232 L 162.93981,433.11336 9.6557406,279.83948 c -12.8743209,-12.88768 -12.8743209,-33.768 0,-46.64456 L 233.20978,9.65592 c 12.87017,-12.87456 33.74338,-12.87456 46.63305,0 l 222.49828,222.50316 c 12.87852,12.87876 12.87852,33.76968 0,46.64456"/></svg>';
|
||||
$label = '<span class="tracy-label" style="'.$style.'">'.$this->getBranchName().'</span>';
|
||||
|
||||
return $icon.$label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders HTML code for custom panel.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPanel(): string
|
||||
{
|
||||
if ($this->isUnderVersionControl()) {
|
||||
$title = '<h1>GIT</h1>';
|
||||
$warning = '';
|
||||
$cntTable = '';
|
||||
|
||||
if ($this->getBranchName() === 'master' || $this->getBranchName() === 'staging') {
|
||||
$warning = '<p style="color: #dd4742; font-weight: 700;">You are working in '.$this->getBranchName().' branch</p>';
|
||||
}
|
||||
|
||||
// commit message
|
||||
if ($this->getLastCommitMessage() !== null) {
|
||||
$cntTable .= '<tr><td>Last commit</td><td> '.$this->getLastCommitMessage().' </td></tr>';
|
||||
}
|
||||
|
||||
// heads
|
||||
if ($this->getHeads() !== null) {
|
||||
$cntTable .= '<tr><td>Branches</td><td> '.$this->getHeads().' </td></tr>';
|
||||
}
|
||||
|
||||
// remotes
|
||||
if ($this->getRemotes() !== null) {
|
||||
$cntTable .= '<tr><td>Remotes</td><td> '.$this->getRemotes().' </td></tr>';
|
||||
}
|
||||
|
||||
// tags
|
||||
if ($this->getTags() !== null && !empty($this->getTags())) {
|
||||
$cntTable .= '<tr><td>Tags</td><td> '.$this->getTags().' </td></tr>';
|
||||
}
|
||||
|
||||
$content = '<div class=\"tracy-inner tracy-InfoPanel\"><table><tbody>'.
|
||||
$cntTable.
|
||||
'</tbody></table></div>';
|
||||
|
||||
return $title.$warning.$content;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
protected function getBranchName(): string
|
||||
{
|
||||
$dir = $this->getDirectory();
|
||||
|
||||
$head = $dir.'/.git/HEAD';
|
||||
if ($dir && is_readable($head)) {
|
||||
$branch = file_get_contents($head);
|
||||
if (strpos($branch, 'ref:') === 0) {
|
||||
$parts = explode('/', $branch);
|
||||
|
||||
return substr($parts[2], 0, -1);
|
||||
}
|
||||
|
||||
return '('.substr($branch, 0, 7).'…)';
|
||||
}
|
||||
|
||||
return 'not versioned';
|
||||
}
|
||||
|
||||
protected function getLastCommitMessage()
|
||||
{
|
||||
$dir = $this->getDirectory();
|
||||
|
||||
$fileMessage = $dir.'/.git/COMMIT_EDITMSG';
|
||||
|
||||
if ($dir && is_readable($fileMessage)) {
|
||||
$message = file_get_contents($fileMessage);
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function getHeads()
|
||||
{
|
||||
$dir = $this->getDirectory();
|
||||
|
||||
$files = scandir($dir.'/.git/refs/heads');
|
||||
$message = '';
|
||||
|
||||
if ($dir && is_array($files)) {
|
||||
foreach ($files as $file) {
|
||||
if ($file !== '.' && $file !== '..') {
|
||||
if ($file === $this->getBranchName()) {
|
||||
$message .= '<strong>'.$file.' </strong>';
|
||||
} else {
|
||||
$message .= $file.' <br>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function getRemotes()
|
||||
{
|
||||
$dir = $this->getDirectory();
|
||||
|
||||
try {
|
||||
$files = scandir($dir.'/.git/refs/remotes');
|
||||
} catch (\ErrorException $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$message = '';
|
||||
|
||||
if ($dir && is_array($files)) {
|
||||
foreach ($files as $file) {
|
||||
if ($file !== '.' && $file !== '..') {
|
||||
$message .= $file.' ';
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function getTags()
|
||||
{
|
||||
$dir = $this->getDirectory();
|
||||
|
||||
$files = scandir($dir.'/.git/refs/tags');
|
||||
$message = '';
|
||||
|
||||
if ($dir && is_array($files)) {
|
||||
foreach ($files as $file) {
|
||||
if ($file !== '.' && $file !== '..') {
|
||||
$message .= $file.' ';
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getDirectory(): string
|
||||
{
|
||||
$scriptPath = $_SERVER['SCRIPT_FILENAME'];
|
||||
|
||||
$dir = realpath(dirname($scriptPath));
|
||||
while ($dir !== false && !is_dir($dir.'/.git')) {
|
||||
flush();
|
||||
$currentDir = $dir;
|
||||
$dir .= '/..';
|
||||
$dir = realpath($dir);
|
||||
|
||||
// Stop recursion to parent on root directory
|
||||
if ($dir === $currentDir) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $dir;
|
||||
}
|
||||
|
||||
private function isUnderVersionControl(): bool
|
||||
{
|
||||
$dir = $this->getDirectory();
|
||||
$head = $dir.'/.git/HEAD';
|
||||
|
||||
if ($dir && is_readable($head)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
namespace FuzeWorks;
|
||||
|
||||
use FuzeWorks\Exception\EventException;
|
||||
use FuzeWorks\Exception\Exception;
|
||||
|
||||
/**
|
||||
|
@ -55,7 +56,7 @@ class Logger {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $Logs = array();
|
||||
public static $logs = [];
|
||||
|
||||
/**
|
||||
* whether to output the log after FuzeWorks has run.
|
||||
|
@ -83,7 +84,7 @@ class Logger {
|
|||
*
|
||||
* @var string Template name
|
||||
*/
|
||||
private static $logger_template = 'logger_default';
|
||||
private static $logger_template = 'logger_cli';
|
||||
|
||||
/**
|
||||
* whether to output the log after FuzeWorks has run, regardless of conditions.
|
||||
|
@ -97,14 +98,7 @@ class Logger {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $markPoints = array();
|
||||
|
||||
/**
|
||||
* Whether to use the Tracy debugger instead of FuzeWorks Logger
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $useTracy = false;
|
||||
public static $markPoints = [];
|
||||
|
||||
/**
|
||||
* Initiates the Logger.
|
||||
|
@ -120,29 +114,69 @@ class Logger {
|
|||
// @codeCoverageIgnoreStart
|
||||
if ($cfg_error->fuzeworks_error_reporting == true)
|
||||
{
|
||||
set_error_handler(array('\FuzeWorks\Logger', 'errorHandler'), E_ALL);
|
||||
set_Exception_handler(array('\FuzeWorks\Logger', 'exceptionHandler'));
|
||||
self::enableHandlers();
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
// Set PHP error reporting
|
||||
if (!$cfg_error->php_error_reporting)
|
||||
error_reporting(false);
|
||||
else
|
||||
if ($cfg_error->php_error_reporting)
|
||||
error_reporting(true);
|
||||
else
|
||||
error_reporting(false);
|
||||
|
||||
// Set the environment variables
|
||||
self::$debug = (ENVIRONMENT === 'DEVELOPMENT');
|
||||
self::$log_last_request = $cfg_error->log_last_request_to_file;
|
||||
self::$log_errors_to_file = $cfg_error->log_errors_to_file;
|
||||
self::$logger_template = $cfg_error->logger_template;
|
||||
self::newLevel('Logger Initiated');
|
||||
}
|
||||
|
||||
if (self::$useTracy)
|
||||
{
|
||||
LoggerTracyBridge::register();
|
||||
GitTracyBridge::register();
|
||||
}
|
||||
/**
|
||||
* Enable error to screen logging.
|
||||
*/
|
||||
public static function enable()
|
||||
{
|
||||
self::$print_to_screen = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable error to screen logging.
|
||||
*/
|
||||
public static function disable()
|
||||
{
|
||||
self::$print_to_screen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether screen logging is enabled.
|
||||
*/
|
||||
public static function isEnabled(): bool
|
||||
{
|
||||
return self::$print_to_screen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable FuzeWorks error handling
|
||||
*
|
||||
* Registers errorHandler() and exceptionHandler() as the respective handlers for PHP
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function enableHandlers()
|
||||
{
|
||||
set_error_handler(array('\FuzeWorks\Logger', 'errorHandler'), E_ALL);
|
||||
set_exception_handler(array('\FuzeWorks\Logger', 'exceptionHandler'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable FuzeWorks error handling
|
||||
*
|
||||
* Unregisters errorHandler() and exceptionHandler() as the respective handlers for PHP
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function disableHandlers()
|
||||
{
|
||||
restore_error_handler();
|
||||
restore_exception_handler();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,26 +214,20 @@ class Logger {
|
|||
*/
|
||||
public static function shutdownError()
|
||||
{
|
||||
// Load last error if thrown
|
||||
$errfile = 'Unknown file';
|
||||
$errstr = 'shutdown';
|
||||
$errno = E_CORE_ERROR;
|
||||
$errline = 0;
|
||||
|
||||
$error = error_get_last();
|
||||
if ($error !== null) {
|
||||
$errno = $error['type'];
|
||||
$errfile = $error['file'];
|
||||
$errline = $error['line'];
|
||||
$errstr = $error['message'];
|
||||
|
||||
// Log it!
|
||||
$thisType = self::getType($errno);
|
||||
self::errorHandler($errno, $errstr, $errfile, $errline);
|
||||
// Log it!
|
||||
$thisType = self::getType($error['type']);
|
||||
$LOG = array('type' => $error['type'],
|
||||
'message' => $error['message'],
|
||||
'logFile' => $error['file'],
|
||||
'logLine' => $error['line'],
|
||||
'runtime' => round(self::getRelativeTime(), 4),);
|
||||
self::$logs[] = $LOG;
|
||||
|
||||
if ($thisType == 'ERROR')
|
||||
{
|
||||
self::http_error('500');
|
||||
self::haltExecution($LOG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -213,7 +241,7 @@ class Logger {
|
|||
* @param int Line. The line on which the error occured.
|
||||
* @param array context. Some of the error's relevant variables
|
||||
*/
|
||||
public static function errorHandler($type = E_USER_NOTICE, $error = 'Undefined Error', $errFile = null, $errLine = null, $context = null)
|
||||
public static function errorHandler($type = E_USER_NOTICE, $error = 'Undefined Error', $errFile = null, $errLine = null)
|
||||
{
|
||||
// Check type
|
||||
$thisType = self::getType($type);
|
||||
|
@ -221,9 +249,8 @@ class Logger {
|
|||
'message' => (!is_null($error) ? $error : ''),
|
||||
'logFile' => (!is_null($errFile) ? $errFile : ''),
|
||||
'logLine' => (!is_null($errLine) ? $errLine : ''),
|
||||
'context' => (!is_null($context) ? $context : ''),
|
||||
'runtime' => round(self::getRelativeTime(), 4),);
|
||||
self::$Logs[] = $LOG;
|
||||
self::$logs[] = $LOG;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,16 +262,16 @@ class Logger {
|
|||
*/
|
||||
public static function exceptionHandler($exception)
|
||||
{
|
||||
$message = $exception->getMessage();
|
||||
$code = $exception->getCode();
|
||||
$file = $exception->getFile();
|
||||
$line = $exception->getLine();
|
||||
$context = $exception->getTraceAsString();
|
||||
$LOG = array('type' => 'EXCEPTION',
|
||||
'message' => $exception->getMessage(),
|
||||
'logFile' => $exception->getFile(),
|
||||
'logLine' => $exception->getLine(),
|
||||
'context' => $exception->getTraceAsString(),
|
||||
'runtime' => round(self::getRelativeTime(), 4),);
|
||||
self::$logs[] = $LOG;
|
||||
|
||||
self::logError('Exception thrown: ' . $message . ' | ' . $code, null, $file, $line);
|
||||
|
||||
// And return a 500 because this error was fatal
|
||||
self::http_error('500');
|
||||
self::haltExecution($LOG);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -268,10 +295,10 @@ class Logger {
|
|||
// Send a screenLogEvent, allows for new screen log designs
|
||||
$event = Events::fireEvent('screenLogEvent');
|
||||
if ($event->isCancelled()) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
$logs = self::$Logs;
|
||||
$logs = self::$logs;
|
||||
require(dirname(__DIR__) . DS . 'Layout' . DS . 'layout.' . self::$logger_template . '.php');
|
||||
}
|
||||
|
||||
|
@ -282,7 +309,7 @@ class Logger {
|
|||
public static function logLastRequest()
|
||||
{
|
||||
ob_start(function () {});
|
||||
$logs = self::$Logs;
|
||||
$logs = self::$logs;
|
||||
require(dirname(__DIR__) . DS . 'Layout' . DS . 'layout.logger_file.php');
|
||||
$contents = ob_get_clean();
|
||||
$file = Core::$logDir . DS . 'fwlog_request.log';
|
||||
|
@ -292,14 +319,14 @@ class Logger {
|
|||
}
|
||||
|
||||
/**
|
||||
* Output all erros to a file. Used for tracking all errors in FuzeWorks and associated code
|
||||
* Output all errors to a file. Used for tracking all errors in FuzeWorks and associated code
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function logErrorsToFile()
|
||||
{
|
||||
ob_start(function() {});
|
||||
$logs = [];
|
||||
foreach (self::$Logs as $log)
|
||||
foreach (self::$logs as $log)
|
||||
{
|
||||
if ($log['type'] === 'ERROR')
|
||||
$logs[] = $log;
|
||||
|
@ -314,7 +341,7 @@ class Logger {
|
|||
/* =========================================LOGGING METHODS============================================================== */
|
||||
|
||||
/**
|
||||
* Set a benchmark markpoint.
|
||||
* Set a benchmark mark point.
|
||||
*
|
||||
* Multiple calls to this function can be made so that several
|
||||
* execution points can be timed.
|
||||
|
@ -331,7 +358,7 @@ class Logger {
|
|||
'context' => '',
|
||||
'runtime' => round(self::getRelativeTime(), 4),);
|
||||
|
||||
self::$Logs[] = $LOG;
|
||||
self::$logs[] = $LOG;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -339,10 +366,10 @@ class Logger {
|
|||
*
|
||||
* @param string $msg The information to be logged
|
||||
* @param string $mod The name of the module
|
||||
* @param string $file The file where the log occured
|
||||
* @param int $line The line where the log occured
|
||||
* @param string $file The file where the log occurred
|
||||
* @param int $line The line where the log occurred
|
||||
*/
|
||||
public static function log($msg, $mod = null, $file = 0, $line = 0)
|
||||
public static function log($msg, $mod = null, $file = null, $line = null)
|
||||
{
|
||||
self::logInfo($msg, $mod, $file, $line);
|
||||
}
|
||||
|
@ -352,10 +379,10 @@ class Logger {
|
|||
*
|
||||
* @param string $msg The information to be logged
|
||||
* @param string $mod The name of the module
|
||||
* @param string $file The file where the log occured
|
||||
* @param int $line The line where the log occured
|
||||
* @param string $file The file where the log occurred
|
||||
* @param int $line The line where the log occurred
|
||||
*/
|
||||
public static function logInfo($msg, $mod = null, $file = 0, $line = 0)
|
||||
public static function logInfo($msg, $mod = null, $file = null, $line = null)
|
||||
{
|
||||
$LOG = array('type' => 'INFO',
|
||||
'message' => (!is_null($msg) ? $msg : ''),
|
||||
|
@ -364,7 +391,7 @@ class Logger {
|
|||
'context' => (!is_null($mod) ? $mod : ''),
|
||||
'runtime' => round(self::getRelativeTime(), 4),);
|
||||
|
||||
self::$Logs[] = $LOG;
|
||||
self::$logs[] = $LOG;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -372,10 +399,10 @@ class Logger {
|
|||
*
|
||||
* @param string $msg The information to be logged
|
||||
* @param string $mod The name of the module
|
||||
* @param string $file The file where the log occured
|
||||
* @param int $line The line where the log occured
|
||||
* @param string $file The file where the log occurred
|
||||
* @param int $line The line where the log occurred
|
||||
*/
|
||||
public static function logDebug($msg, $mod = null, $file = 0, $line = 0)
|
||||
public static function logDebug($msg, $mod = null, $file = null, $line = null)
|
||||
{
|
||||
$LOG = array('type' => 'DEBUG',
|
||||
'message' => (!is_null($msg) ? $msg : ''),
|
||||
|
@ -384,7 +411,7 @@ class Logger {
|
|||
'context' => (!is_null($mod) ? $mod : ''),
|
||||
'runtime' => round(self::getRelativeTime(), 4),);
|
||||
|
||||
self::$Logs[] = $LOG;
|
||||
self::$logs[] = $LOG;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -392,10 +419,10 @@ class Logger {
|
|||
*
|
||||
* @param string $msg The information to be logged
|
||||
* @param string $mod The name of the module
|
||||
* @param string $file The file where the log occured
|
||||
* @param int $line The line where the log occured
|
||||
* @param string $file The file where the log occurred
|
||||
* @param int $line The line where the log occurred
|
||||
*/
|
||||
public static function logError($msg, $mod = null, $file = 0, $line = 0)
|
||||
public static function logError($msg, $mod = null, $file = null, $line = null)
|
||||
{
|
||||
$LOG = array('type' => 'ERROR',
|
||||
'message' => (!is_null($msg) ? $msg : ''),
|
||||
|
@ -404,7 +431,7 @@ class Logger {
|
|||
'context' => (!is_null($mod) ? $mod : ''),
|
||||
'runtime' => round(self::getRelativeTime(), 4),);
|
||||
|
||||
self::$Logs[] = $LOG;
|
||||
self::$logs[] = $LOG;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -412,10 +439,10 @@ class Logger {
|
|||
*
|
||||
* @param string $msg The information to be logged
|
||||
* @param string $mod The name of the module
|
||||
* @param string $file The file where the log occured
|
||||
* @param int $line The line where the log occured
|
||||
* @param string $file The file where the log occurred
|
||||
* @param int $line The line where the log occurred
|
||||
*/
|
||||
public static function logWarning($msg, $mod = null, $file = 0, $line = 0)
|
||||
public static function logWarning($msg, $mod = null, $file = null, $line = null)
|
||||
{
|
||||
$LOG = array('type' => 'WARNING',
|
||||
'message' => (!is_null($msg) ? $msg : ''),
|
||||
|
@ -424,7 +451,7 @@ class Logger {
|
|||
'context' => (!is_null($mod) ? $mod : ''),
|
||||
'runtime' => round(self::getRelativeTime(), 4),);
|
||||
|
||||
self::$Logs[] = $LOG;
|
||||
self::$logs[] = $LOG;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -432,8 +459,8 @@ class Logger {
|
|||
*
|
||||
* @param string $msg The name of the new level
|
||||
* @param string $mod The name of the module
|
||||
* @param string $file The file where the log occured
|
||||
* @param int $line The line where the log occured
|
||||
* @param string $file The file where the log occurred
|
||||
* @param int $line The line where the log occurred
|
||||
*/
|
||||
public static function newLevel($msg, $mod = null, $file = null, $line = null)
|
||||
{
|
||||
|
@ -444,7 +471,7 @@ class Logger {
|
|||
'context' => (!is_null($mod) ? $mod : ''),
|
||||
'runtime' => round(self::getRelativeTime(), 4),);
|
||||
|
||||
self::$Logs[] = $LOG;
|
||||
self::$logs[] = $LOG;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -452,8 +479,8 @@ class Logger {
|
|||
*
|
||||
* @param string $msg The name of the new level
|
||||
* @param string $mod The name of the module
|
||||
* @param string $file The file where the log occured
|
||||
* @param int $line The line where the log occured
|
||||
* @param string $file The file where the log occurred
|
||||
* @param int $line The line where the log occurred
|
||||
*/
|
||||
public static function stopLevel($msg = null, $mod = null, $file = null, $line = null)
|
||||
{
|
||||
|
@ -464,7 +491,7 @@ class Logger {
|
|||
'context' => (!is_null($mod) ? $mod : ''),
|
||||
'runtime' => round(self::getRelativeTime(), 4),);
|
||||
|
||||
self::$Logs[] = $LOG;
|
||||
self::$logs[] = $LOG;
|
||||
}
|
||||
|
||||
/* =========================================OTHER METHODS============================================================== */
|
||||
|
@ -473,7 +500,7 @@ class Logger {
|
|||
* Returns a string representation of an error
|
||||
* Turns a PHP error-constant (or integer) into a string representation.
|
||||
*
|
||||
* @param int $type PHP-constant errortype (e.g. E_NOTICE).
|
||||
* @param int $type PHP-constant errorType (e.g. E_NOTICE).
|
||||
*
|
||||
* @return string String representation
|
||||
*/
|
||||
|
@ -516,93 +543,25 @@ class Logger {
|
|||
}
|
||||
|
||||
/**
|
||||
* Calls an HTTP error, sends it as a header, and loads a template if required to do so.
|
||||
* Halts the Execution of FuzeWorks
|
||||
*
|
||||
* @param int $errno HTTP error code
|
||||
* @param string $message Message describing the reason for the HTTP error
|
||||
* @param bool $layout true to layout error on website
|
||||
* Will die a message if not intercepted by haltExecutionEvent.
|
||||
* @param array $log
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function http_error($errno = 500, $message = '', $layout = true): bool
|
||||
public static function haltExecution(array $log)
|
||||
{
|
||||
$http_codes = array(
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Timeout',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
418 => 'I\'m a teapot',
|
||||
426 => 'Upgrade Required',
|
||||
428 => 'Precondition Required',
|
||||
429 => 'Too Many Requests',
|
||||
431 => 'Request Header Fields Too Large',
|
||||
500 => 'Internal Server Error',
|
||||
501 => 'Not Implemented',
|
||||
502 => 'Bad Gateway',
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Timeout',
|
||||
505 => 'HTTP Version Not Supported',
|
||||
506 => 'Variant Also Negotiates',
|
||||
509 => 'Bandwidth Limit Exceeded',
|
||||
510 => 'Not Extended',
|
||||
511 => 'Network Authentication Required',
|
||||
);
|
||||
|
||||
self::logError('HTTP-error ' . $errno . ' called');
|
||||
self::log('Sending header HTTP/1.1 ' . $errno . ' ' . $http_codes[$errno]);
|
||||
header('HTTP/1.1 ' . $errno . ' ' . $http_codes[$errno]);
|
||||
|
||||
// Set the status code
|
||||
Core::$http_status_code = $errno;
|
||||
|
||||
// Do we want the error-layout with it?
|
||||
if ($layout == false) {
|
||||
return false;
|
||||
self::logError("Halting execution...");
|
||||
try {
|
||||
$event = Events::fireEvent("haltExecutionEvent", $log);
|
||||
} catch (EventException $e) {
|
||||
self::logError("Can't fire haltExecutionEvent: '".$e->getMessage()."'");
|
||||
die(PHP_EOL . "FuzeWorks execution halted. See error log for more information");
|
||||
}
|
||||
if ($event->isCancelled() == true)
|
||||
return;
|
||||
|
||||
// Load the layout
|
||||
$layout = 'errors/' . $errno;
|
||||
self::log('Loading layout ' . $layout);
|
||||
|
||||
// Try and load the layout, if impossible, load HTTP code instead.
|
||||
echo "<h1>$errno</h1><h3>" . $http_codes[$errno] . '</h3><p>' . $message . '</p>';
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable error to screen logging.
|
||||
*/
|
||||
public static function enable()
|
||||
{
|
||||
self::$print_to_screen = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable error to screen logging.
|
||||
*/
|
||||
public static function disable()
|
||||
{
|
||||
self::$print_to_screen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether screen logging is enabled.
|
||||
*/
|
||||
public static function isEnabled(): bool
|
||||
{
|
||||
return self::$print_to_screen;
|
||||
die(PHP_EOL . "FuzeWorks execution halted. See error log for more information");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework Core.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
use Tracy\IBarPanel;
|
||||
use Tracy\Debugger;
|
||||
|
||||
/**
|
||||
* LoggerTracyBridge Class.
|
||||
*
|
||||
* This class provides a bridge between FuzeWorks\Logger and Tracy Debugging tool.
|
||||
*
|
||||
* This class registers in Tracy, and creates a Bar object which contains the log.
|
||||
* Afterwards it blocks a screen log so that the content is not shown on the screen as well.
|
||||
*
|
||||
* @author TechFuze <contact@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
*/
|
||||
class LoggerTracyBridge implements IBarPanel {
|
||||
|
||||
/**
|
||||
* Register the bar and register the event which will block the screen log
|
||||
*/
|
||||
public static function register()
|
||||
{
|
||||
$class = new self();
|
||||
Events::addListener(array($class, 'screenLogEventListener'), 'screenLogEvent', EventPriority::NORMAL);
|
||||
$bar = Debugger::getBar();
|
||||
$bar->addPanel($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener that blocks the screen log
|
||||
*
|
||||
* @param Event
|
||||
* @return Event
|
||||
*/
|
||||
public function screenLogEventListener($event): Event
|
||||
{
|
||||
$event->setCancelled(true);
|
||||
return $event;
|
||||
}
|
||||
|
||||
public function getTab(): string
|
||||
{
|
||||
ob_start(function () {});
|
||||
require dirname(__DIR__) . DS . 'Layout' . DS . 'layout.tracyloggertab.php';
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public function getPanel(): string
|
||||
{
|
||||
// If an error is thrown, log it
|
||||
$errfile = 'Unknown file';
|
||||
$errstr = 'shutdown';
|
||||
$errno = E_CORE_ERROR;
|
||||
$errline = 0;
|
||||
|
||||
$error = error_get_last();
|
||||
if ($error !== null) {
|
||||
$errno = $error['type'];
|
||||
$errfile = $error['file'];
|
||||
$errline = $error['line'];
|
||||
$errstr = $error['message'];
|
||||
|
||||
// Log it!
|
||||
Logger::errorHandler($errno, $errstr, $errfile, $errline);
|
||||
}
|
||||
|
||||
// Reverse the logs
|
||||
$logs = array_reverse(Logger::$Logs, true);
|
||||
|
||||
// Parse the panel
|
||||
ob_start(function () {});
|
||||
require dirname(__DIR__) . DS . 'Layout' . DS . 'layout.tracyloggerpanel.php';
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
}
|
|
@ -41,6 +41,6 @@ namespace FuzeWorks;
|
|||
interface iComponent
|
||||
{
|
||||
public function getClasses(): array;
|
||||
public function onAddComponent(Configurator $configurator): Configurator;
|
||||
public function onCreateContainer(Configurator $configurator): Configurator;
|
||||
public function onAddComponent(Configurator $configurator);
|
||||
public function onCreateContainer(Factory $container);
|
||||
}
|
|
@ -104,6 +104,11 @@ foreach ($logs as $log) {
|
|||
$string .= getColoredString('[ERROR]', 'black', 'red') . ' - ';
|
||||
$string .= getColoredString($log['message'], 'black', 'red');
|
||||
}
|
||||
elseif ($log['type'] == 'EXCEPTION')
|
||||
{
|
||||
$string .= getColoredString('[EXCEPTION]', 'black', 'red') . ' - ';
|
||||
$string .= getColoredString($log['message'], 'black', 'red');
|
||||
}
|
||||
elseif ($log['type'] == "LEVEL_STOP")
|
||||
{
|
||||
continue;
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework Core.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
?>
|
||||
<style class="tracy-debug">
|
||||
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
<div class="fuzeworks-LoggerPanel">
|
||||
<h1> Logger</h1>
|
||||
|
||||
<div class="tracy-inner">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Type</th>
|
||||
<th>Message</th>
|
||||
<th>File</th>
|
||||
<th>Line</th>
|
||||
<th>Timing</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<?php foreach ($logs as $key => $log): ?>
|
||||
<?php if ($log['type'] === 'LEVEL_STOP')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
elseif ($log['type'] === 'LEVEL_START')
|
||||
{
|
||||
$log['type'] = 'CINFO';
|
||||
}
|
||||
?>
|
||||
<tr class="<?php echo($log['type']); ?>">
|
||||
<td><?php echo( htmlspecialchars($key)); ?></td>
|
||||
<td><?php echo( htmlspecialchars ($log['type'])); ?></td>
|
||||
<td><?php echo( htmlspecialchars ($log['message'])); ?></td>
|
||||
<td><?php echo( empty($log['logFile']) ? 'x' : htmlspecialchars ($log['logFile'])); ?></td>
|
||||
<td><?php echo( empty($log['logLine']) ? 'x' : htmlspecialchars ($log['logLine'])); ?></td>
|
||||
<td><?php echo(round($log['runtime'] * 1000, 4)); ?> ms</td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
|
@ -43,15 +43,11 @@ chdir(dirname(__DIR__));
|
|||
|
||||
// Load the FuzeWorks container
|
||||
$container = require('bootstrap.php');
|
||||
Logger::disableHandlers();
|
||||
|
||||
// Load the test abstract
|
||||
require_once 'core/abstract.coreTestAbstract.php';
|
||||
|
||||
// Reset error and exception handlers
|
||||
ob_start();
|
||||
restore_error_handler();
|
||||
restore_exception_handler();
|
||||
|
||||
// Display all errors
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
*/
|
||||
namespace FuzeWorks\Component;
|
||||
use FuzeWorks\Configurator;
|
||||
use FuzeWorks\Factory;
|
||||
use FuzeWorks\iComponent;
|
||||
|
||||
class TestComponent implements iComponent
|
||||
|
@ -50,9 +51,9 @@ class TestComponent implements iComponent
|
|||
return $configurator;
|
||||
}
|
||||
|
||||
public function onCreateContainer(Configurator $configurator): Configurator
|
||||
public function onCreateContainer(Factory $container)
|
||||
{
|
||||
return $configurator;
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
*/
|
||||
namespace FuzeWorks\Component;
|
||||
use FuzeWorks\Configurator;
|
||||
use FuzeWorks\Factory;
|
||||
use FuzeWorks\iComponent;
|
||||
|
||||
class TestAddComponentDirectoryComponent implements iComponent
|
||||
|
@ -50,9 +51,9 @@ class TestAddComponentDirectoryComponent implements iComponent
|
|||
return $configurator;
|
||||
}
|
||||
|
||||
public function onCreateContainer(Configurator $configurator): Configurator
|
||||
public function onCreateContainer(Factory $container)
|
||||
{
|
||||
return $configurator;
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
*/
|
||||
namespace FuzeWorks\Component;
|
||||
use FuzeWorks\Configurator;
|
||||
use FuzeWorks\Factory;
|
||||
use FuzeWorks\iComponent;
|
||||
|
||||
class TestAddComponentFailComponent implements iComponent
|
||||
|
@ -50,9 +51,9 @@ class TestAddComponentFailComponent implements iComponent
|
|||
return $configurator;
|
||||
}
|
||||
|
||||
public function onCreateContainer(Configurator $configurator): Configurator
|
||||
public function onCreateContainer(Factory $container)
|
||||
{
|
||||
return $configurator;
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,9 +57,6 @@ abstract class CoreTestAbstract extends TestCase
|
|||
// Clear all events created by tests
|
||||
Events::$listeners = array();
|
||||
|
||||
// Re-register the LoggerTracyBridge to suppress errors
|
||||
LoggerTracyBridge::register();
|
||||
|
||||
// Reset all config files
|
||||
Factory::getInstance()->config->discardConfigFiles();
|
||||
|
||||
|
|
|
@ -130,6 +130,27 @@ class configTest extends CoreTestAbstract
|
|||
$this->assertEquals(['initial' => 'different'], $this->config->getConfig('testLoadConfigOverride', ['test'.DS.'config'.DS.'TestLoadConfigOverride'])->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testLoadConfigOverride
|
||||
* @covers \FuzeWorks\Config::overrideConfig
|
||||
* @covers \FuzeWorks\Config::loadConfigFile
|
||||
*/
|
||||
public function testLoadConfigCoreOverride()
|
||||
{
|
||||
// First see that it does not exist
|
||||
$this->assertFalse(isset($this->config->getConfig('error')->toArray()['someKey']));
|
||||
|
||||
// Then discard to reset the test
|
||||
$this->config->discardConfigFiles();
|
||||
|
||||
// Create the override
|
||||
Config::overrideConfig('error', 'someKey', 'someValue');
|
||||
|
||||
// And test that it exists now
|
||||
$this->assertTrue(isset($this->config->getConfig('error')->toArray()['someKey']));
|
||||
$this->assertEquals('someValue', $this->config->getConfig('error')->toArray()['someKey']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException FuzeWorks\Exception\ConfigException
|
||||
*/
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
use FuzeWorks\Configurator;
|
||||
use FuzeWorks\Core;
|
||||
use FuzeWorks\Factory;
|
||||
use FuzeWorks\iComponent;
|
||||
use FuzeWorks\Logger;
|
||||
|
||||
|
@ -366,7 +367,7 @@ class configuratorTest extends CoreTestAbstract
|
|||
|
||||
// Load the container and verify that tracy runs in debug mode
|
||||
$this->configurator->createContainer()->init();
|
||||
$this->assertTrue(\Tracy\Debugger::isEnabled());
|
||||
$this->assertTrue(Logger::isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -444,19 +445,6 @@ class configuratorTest extends CoreTestAbstract
|
|||
{
|
||||
$this->configurator->setDebugAddress(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testEnableDebugMode
|
||||
*/
|
||||
public function testSetDebugEmail()
|
||||
{
|
||||
// Set email and verify return value
|
||||
$this->assertInstanceOf('FuzeWorks\Configurator', $this->configurator->setDebugEmail('test@email.com'));
|
||||
|
||||
// Create container and test Tracy for set address
|
||||
$this->configurator->createContainer()->init();
|
||||
$this->assertEquals('test@email.com', \Tracy\Debugger::$email);
|
||||
}
|
||||
}
|
||||
|
||||
class MockComponent implements iComponent
|
||||
|
@ -471,9 +459,9 @@ class MockComponent implements iComponent
|
|||
return $configurator;
|
||||
}
|
||||
|
||||
public function onCreateContainer(Configurator $configurator): Configurator
|
||||
public function onCreateContainer(Factory $container)
|
||||
{
|
||||
return $configurator;
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Events;
|
||||
use FuzeWorks\Logger;
|
||||
use FuzeWorks\Factory;
|
||||
use FuzeWorks\Exception\LoggerException;
|
||||
|
@ -52,7 +53,7 @@ class loggerTest extends CoreTestAbstract
|
|||
public function setUp()
|
||||
{
|
||||
Factory::getInstance()->config->get('error')->fuzeworks_error_reporting = false;
|
||||
Logger::$Logs = array();
|
||||
Logger::$logs = array();
|
||||
}
|
||||
|
||||
public function testGetLogger()
|
||||
|
@ -64,15 +65,14 @@ class loggerTest extends CoreTestAbstract
|
|||
|
||||
public function testErrorHandler()
|
||||
{
|
||||
Logger::errorHandler(E_ERROR, 'Example error', __FILE__, 1, 'data');
|
||||
$this->assertCount(1, Logger::$Logs);
|
||||
Logger::errorHandler(E_ERROR, 'Example error', __FILE__, 1);
|
||||
$this->assertCount(1, Logger::$logs);
|
||||
|
||||
$log = Logger::$Logs[0];
|
||||
$log = Logger::$logs[0];
|
||||
$this->assertEquals('ERROR', $log['type']);
|
||||
$this->assertEquals('Example error', $log['message']);
|
||||
$this->assertEquals(__FILE__, $log['logFile']);
|
||||
$this->assertEquals(1, $log['logLine']);
|
||||
$this->assertEquals('data', $log['context']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,13 +101,13 @@ class loggerTest extends CoreTestAbstract
|
|||
|
||||
foreach ($types as $errorType => $output) {
|
||||
// Clear the log entries
|
||||
Logger::$Logs = array();
|
||||
Logger::$logs = array();
|
||||
|
||||
// Log the error
|
||||
Logger::errorHandler($errorType, 'Log message');
|
||||
|
||||
// Fetch the error
|
||||
$log = Logger::$Logs[0];
|
||||
$log = Logger::$logs[0];
|
||||
|
||||
// Check the type
|
||||
$this->assertEquals($output, $log['type']);
|
||||
|
@ -117,17 +117,16 @@ class loggerTest extends CoreTestAbstract
|
|||
public function testExceptionHandler()
|
||||
{
|
||||
// Create the exception
|
||||
$exception = new LoggerException();
|
||||
$exception = new LoggerException("FAILURE");
|
||||
|
||||
// Prepare to intercept
|
||||
Events::addListener(function($event){
|
||||
$event->setCancelled(true);
|
||||
$this->assertEquals('FAILURE', $event->log['message']);
|
||||
}, 'haltExecutionEvent');
|
||||
|
||||
// Log the exception
|
||||
ob_start();
|
||||
Logger::exceptionHandler($exception);
|
||||
|
||||
// Check the output
|
||||
$this->assertEquals('<h1>500</h1><h3>Internal Server Error</h3><p></p>', ob_get_clean());
|
||||
|
||||
// Check the logs
|
||||
$log = Logger::$Logs[0];
|
||||
}
|
||||
|
||||
public function testLog()
|
||||
|
@ -136,7 +135,7 @@ class loggerTest extends CoreTestAbstract
|
|||
Logger::log('Log message', 'core_loggerTest', __FILE__, 1);
|
||||
|
||||
// Fetch the message
|
||||
$log = Logger::$Logs[0];
|
||||
$log = Logger::$logs[0];
|
||||
|
||||
// Assert data
|
||||
$this->assertEquals('INFO', $log['type']);
|
||||
|
@ -162,76 +161,19 @@ class loggerTest extends CoreTestAbstract
|
|||
|
||||
foreach ($types as $method => $returnValue) {
|
||||
// Clear the log entries
|
||||
Logger::$Logs = array();
|
||||
Logger::$logs = array();
|
||||
|
||||
// Log the entry
|
||||
Logger::{$method}('Log message', 'core_loggerTest', __FILE__, 1);
|
||||
|
||||
// Fetch the entry
|
||||
$log = Logger::$Logs[0];
|
||||
$log = Logger::$logs[0];
|
||||
|
||||
// Assert the entry
|
||||
$this->assertEquals($returnValue, $log['type']);
|
||||
}
|
||||
}
|
||||
|
||||
public function testHttpError()
|
||||
{
|
||||
$http_codes = array(
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Timeout',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
418 => 'I\'m a teapot',
|
||||
426 => 'Upgrade Required',
|
||||
428 => 'Precondition Required',
|
||||
429 => 'Too Many Requests',
|
||||
431 => 'Request Header Fields Too Large',
|
||||
500 => 'Internal Server Error',
|
||||
501 => 'Not Implemented',
|
||||
502 => 'Bad Gateway',
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Timeout',
|
||||
505 => 'HTTP Version Not Supported',
|
||||
506 => 'Variant Also Negotiates',
|
||||
509 => 'Bandwidth Limit Exceeded',
|
||||
510 => 'Not Extended',
|
||||
511 => 'Network Authentication Required',
|
||||
);
|
||||
|
||||
// Test all error codes
|
||||
foreach ($http_codes as $code => $description) {
|
||||
// Fire the error
|
||||
ob_start();
|
||||
Logger::http_error($code);
|
||||
|
||||
// Check the output
|
||||
$this->assertEquals('<h1>'.$code.'</h1><h3>'.$description.'</h3><p></p>', ob_get_clean());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testHttpError
|
||||
*/
|
||||
public function testHttpErrorWithoutLayout()
|
||||
{
|
||||
$this->assertFalse(Logger::http_error(500, '', false));
|
||||
}
|
||||
|
||||
public function testEnableDisable()
|
||||
{
|
||||
// First enable
|
||||
|
@ -246,6 +188,6 @@ class loggerTest extends CoreTestAbstract
|
|||
public function tearDown()
|
||||
{
|
||||
Logger::disable();
|
||||
Logger::$Logs = array();
|
||||
Logger::$logs = array();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue