Initial Commit
This commit is contained in:
commit
697ac53bf1
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.gitattributes export-ignore
|
||||
.gitignore export-ignore
|
22
.gitignore
vendored
Normal file
22
.gitignore
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# Ignore Coffee/Espresso. We only want chocolate
|
||||
FuzeWorks.esproj/*
|
||||
|
||||
# Ignore PHP Storm
|
||||
.idea/
|
||||
|
||||
# Development files
|
||||
test.php
|
||||
|
||||
# Generic Files
|
||||
*~
|
||||
*.lock
|
||||
*.DS_Store
|
||||
*.swp
|
||||
*.out
|
||||
|
||||
# Build Files
|
||||
vendor/
|
||||
build/
|
||||
doc
|
||||
nbproject
|
||||
._*
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
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.
|
60
README.md
Normal file
60
README.md
Normal file
@ -0,0 +1,60 @@
|
||||
FuzeWorks - Readme
|
||||
===================
|
||||
|
||||
Version 1.2.0
|
||||
|
||||
A versatile PHP Framework built to perform.
|
||||
|
||||
https://techfuze.net/fuzeworks
|
||||
|
||||
Summary
|
||||
-------
|
||||
|
||||
FuzeWorks is a flexible PHP Framework made for the requirements of todays web.
|
||||
For a summary of features, list of requirements, and installation instructions,
|
||||
please see the documentation in the ./doc/ folder or at http://techfuze.net/fuzeworks
|
||||
|
||||
Copyright
|
||||
---------
|
||||
|
||||
Copyright © 2013 onwards -- TechFuze
|
||||
|
||||
Certain libraries are copyrighted by their respective authors;
|
||||
see the full copyright list for details.
|
||||
|
||||
For full copyright information, please see ./doc/copyright.html
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
MIT License
|
||||
|
||||
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.
|
||||
|
||||
Licensing of current contributions
|
||||
----------------------------------
|
||||
|
||||
Beginning on 2018-04-17, new contributions to this codebase are all licensed
|
||||
under terms compatible with the MIT license. FuzeWorks is currently
|
||||
transitioning older code to the MIT License, but work is not yet complete.
|
||||
|
||||
Enjoy!
|
||||
------
|
||||
|
||||
TechFuze
|
29
composer.json
Normal file
29
composer.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "fuzeworks/tracycomponent",
|
||||
"description": "FuzeWorks Framework Tracy Debugger Component",
|
||||
"homepage": "https://techfuze.net/fuzeworks",
|
||||
"license": ["MIT"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "TechFuze",
|
||||
"homepage": "https://techfuze.net"
|
||||
},
|
||||
{
|
||||
"name": "FuzeWorks Community",
|
||||
"homepage": "https://techfuze.net/fuzeworks/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.0",
|
||||
"tracy/tracy": "2.5.*",
|
||||
"fuzeworks/core": "dev-development"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"FuzeWorks\\": "src/FuzeWorks/"
|
||||
}
|
||||
}
|
||||
}
|
261
src/FuzeWorks/GitTracyBridge.php
Normal file
261
src/FuzeWorks/GitTracyBridge.php
Normal file
@ -0,0 +1,261 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Tracy Component.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
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
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
95
src/FuzeWorks/LoggerTracyBridge.php
Normal file
95
src/FuzeWorks/LoggerTracyBridge.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Tracy Component.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
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()
|
||||
{
|
||||
// Register the bar object
|
||||
$class = new self();
|
||||
$bar = Debugger::getBar();
|
||||
$bar->addPanel($class);
|
||||
}
|
||||
|
||||
public function getTab(): string
|
||||
{
|
||||
ob_start(function () {});
|
||||
require dirname(__FILE__) . DS . 'layout.tracyloggertab.php';
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public function getPanel(): string
|
||||
{
|
||||
// If an error is thrown, log it
|
||||
$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(__FILE__) . DS . 'layout.tracyloggerpanel.php';
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
}
|
183
src/FuzeWorks/TracyComponent.php
Normal file
183
src/FuzeWorks/TracyComponent.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Tracy Component.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
use FuzeWorks\Exception\InvalidArgumentException;
|
||||
use Tracy\Debugger;
|
||||
|
||||
/**
|
||||
* TracyComponent Class.
|
||||
*
|
||||
* This class provides a bridge between FuzeWorks\Logger and Tracy Debugging tool.
|
||||
*
|
||||
* This class enables Tracy and disables the FuzeWorks\Logger.
|
||||
* FuzeWorks Logger then redirects its logs to the Tracy Bar. This allows the user to still see FuzeWorks' logs.
|
||||
*
|
||||
* @author TechFuze <contact@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
*/
|
||||
class TracyComponent implements iComponent
|
||||
{
|
||||
|
||||
/**
|
||||
* Whether Tracy is enabled or not
|
||||
*
|
||||
* @var bool $enableTracy
|
||||
*/
|
||||
protected $enableTracy = true;
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'TracyComponent';
|
||||
}
|
||||
|
||||
public function getClasses(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function onAddComponent(Configurator $configurator){}
|
||||
|
||||
/**
|
||||
* Enables Tracy when requested to do so. Disables FuzeWorks Logger.
|
||||
*
|
||||
* @param Factory $container
|
||||
* @throws Exception\EventException
|
||||
*/
|
||||
public function onCreateContainer(Factory $container)
|
||||
{
|
||||
// If Tracy should not be enabled, escape
|
||||
if ($this->enableTracy == false)
|
||||
{
|
||||
Logger::logInfo("TracyComponent added but not enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable screenLog
|
||||
Events::addListener(function($event){
|
||||
$event->setCancelled(true);
|
||||
}, 'screenLogEvent');
|
||||
|
||||
// Enable Tracy. Use DEVELOPMENT mode when logger is enabled
|
||||
if ($container->logger->isEnabled() == true)
|
||||
Debugger::enable(Debugger::DEVELOPMENT, realpath(Core::$logDir));
|
||||
else
|
||||
Debugger::enable(Debugger::PRODUCTION, realpath(Core::$logDir));
|
||||
|
||||
// Disable FuzeWorks Logger
|
||||
$container->logger->disable();
|
||||
|
||||
// Enable bridges
|
||||
GitTracyBridge::register();
|
||||
LoggerTracyBridge::register();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a static method in the Debugger class
|
||||
*
|
||||
* @param $method
|
||||
* @param $arguments
|
||||
* @return mixed
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
if (!method_exists('\Tracy\Debugger', $method))
|
||||
throw new InvalidArgumentException("Could not invoke call on Tracy\Debugger. Method '".$method."' does not exist.");
|
||||
|
||||
return call_user_func_array(['\Tracy\Debugger', $method], $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a property from the Debugger class
|
||||
*
|
||||
* @param $name
|
||||
* @return mixed
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if (!property_exists('\Tracy\Debugger', $name))
|
||||
throw new InvalidArgumentException("Could not get property of Tracy\Debugger. Property does not exist.");
|
||||
|
||||
return Debugger::$$name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a property in the Debugger class
|
||||
*
|
||||
* @param $name
|
||||
* @param $value
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
if (!property_exists('\Tracy\Debugger', $name))
|
||||
throw new InvalidArgumentException("Could not get property of Tracy\Debugger. Property does not exist.");
|
||||
|
||||
Debugger::$$name = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable Tracy
|
||||
*
|
||||
* Has no effect after container is created
|
||||
*/
|
||||
public function enableTracy()
|
||||
{
|
||||
$this->enableTracy = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable Tracy
|
||||
*
|
||||
* Has no effect after container is created
|
||||
*/
|
||||
public function disableTracy()
|
||||
{
|
||||
$this->enableTracy = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether Tracy will be enabled or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->enableTracy;
|
||||
}
|
||||
}
|
82
src/FuzeWorks/layout.tracyloggerpanel.php
Normal file
82
src/FuzeWorks/layout.tracyloggerpanel.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Tracy Component.
|
||||
*
|
||||
* 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
src/FuzeWorks/layout.tracyloggertab.php
Normal file
43
src/FuzeWorks/layout.tracyloggertab.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Tracy Component.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
?>
|
||||
<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>
|
||||
|
Loading…
Reference in New Issue
Block a user