Commit d0598936 authored by Tomáš Pospíšil's avatar Tomáš Pospíšil
Browse files

Add DatabaseInfo

parent c5d20d18
# tracyBars
# TracyBars
## Instalace
Do composer.json přidat
"repositories": [
{
"type": "composer",
"url": "https://composer.praguebest.cz"
}
],
a spustit
composer require praguebest/tracyBars`
V projektu pak registrovat následovně:
use Praguebest\BarPanel\Registrator;
use Praguebest\Tools\WebSwitcherUrls;
use Praguebest\Tools\DatabaseInfo;
Registrator::getInstance(TEMPLATE_COMPILE_DIR, CACHE_DIR)
->registerDebugger(APPLICATION_ROOT . 'errors', EMAIL_DEVELOPER, DEVELOPER_IPS)
->registerWebswitcher(new WebSwitcherUrls('hyundai.pb', 'hyundai.praguebest.cz', 'hyundai.cz'), new DatabaseInfo(DB_NAME, DB_URL_LINK))
->registerDBProfiler();
1) Třídu WTSmarty podědit od třídy TraceableSmarty
2)
- Pro Mastershop: Do Db->query() přidat
`DBProfiler::getInstance()->profile($this->sql, $tookTime);`
Viz např. Harfasport
- Pro Epublisher: Do Database->execute přidat
`return DBProfiler::getInstance()->profilePublisher($this->_statement, $params, $this->_params);`
Viz např. Hyundai
......@@ -10,17 +10,17 @@
}
],
"require": {
"php": "^7.1",
"php": "^7.3",
"ext-dom": "*",
"ext-pdo": "*",
"nette/utils": "^3.0",
"noximo/dbgr": "^0.1.5",
"smarty/smarty": "^3.1",
"tracy/tracy": "^2.7",
"tracy/tracy": "^2.8",
"voku/html-min": "^4.3"
},
"require-dev": {
"ergebnis/composer-normalize": "^1.3.1",
"ergebnis/composer-normalize": "^2.13.2",
"roave/security-advisories": "dev-master"
},
"autoload": {
......
This diff is collapsed.
<?php
declare(strict_types=1);
namespace Praguebest\BarPanel;
use Nette\Utils\Strings;
use Throwable;
use Tracy\IBarPanel;
......@@ -49,7 +49,8 @@ abstract class BaseBarPanel implements IBarPanel
$htmlMin->doKeepHttpAndHttpsPrefixOnExternalAttributes(); // keep "http:"- and "https:"-prefix for all external links
$htmlMin->doRemoveDefaultAttributes(); // remove defaults (depends on "doOptimizeAttributes(true)" | disabled by default)
$htmlMin->doRemoveDeprecatedAnchorName(); // remove deprecated anchor-jump (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedScriptCharsetAttribute(); // remove deprecated charset-attribute - the browser will use the charset from the HTTP-Header, anyway (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedScriptCharsetAttribute();
// remove deprecated charset-attribute - the browser will use the charset from the HTTP-Header, anyway (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedTypeFromScriptTag(); // remove deprecated script-mime-types (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedTypeFromStylesheetLink(); // remove "type=text/css" for css links (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveEmptyAttributes(); // remove some empty attributes (depends on "doOptimizeAttributes(true)")
......
......@@ -8,6 +8,7 @@ use ArrayObject;
use Nette\Utils\FileSystem;
use Nette\Utils\Strings;
use Praguebest\Tools;
use Praguebest\Tools\DatabaseInfo;
use Praguebest\Tools\DBProfiler;
use Praguebest\Tools\Settings\OnOff;
use Praguebest\Tools\Settings\StringSetting;
......@@ -60,17 +61,6 @@ final class Registrator
$this->settings->append(new StringSetting(Tools\Dumper::PROJECT_PATH, 'Local project path'));
}
private function addPanel(string $method, callable $panelCreator): void
{
if (PHP_SAPI !== 'cli' && !array_key_exists($method, self::$registeredPanels) && Debugger::$productionMode === Debugger::DEVELOPMENT) {
$panel = $panelCreator();
assert($panel instanceof IBarPanel);
self::$registeredPanels[$method] = $panel;
Debugger::getBar()->addPanel($panel);
}
}
public static function getInstance(string $compileDir, string $cacheDir): Registrator
{
if (self::$instance === null) {
......@@ -124,6 +114,35 @@ final class Registrator
return $this;
}
/**
* @param array|null $extraIps
* @return array|string[]
*/
private function getIps(?array $extraIps): array
{
$ips = [
'42@84.42.168.182',
'42@185.156.123.46',
'42@178.77.200.253',
];
if ($extraIps !== null) {
$ips = array_merge($ips, $extraIps);
}
return $ips;
}
private function addPanel(string $method, callable $panelCreator): void
{
if (PHP_SAPI !== 'cli' && !array_key_exists($method, self::$registeredPanels) && Debugger::$productionMode === Debugger::DEVELOPMENT) {
$panel = $panelCreator();
assert($panel instanceof IBarPanel);
self::$registeredPanels[$method] = $panel;
Debugger::getBar()->addPanel($panel);
}
}
public function registerAll(Tools\TraceableSmarty $smarty, WebSwitcherUrls $urls): Registrator
{
if (Debugger::isEnabled()) {
......@@ -151,12 +170,12 @@ final class Registrator
return $this;
}
public function registerWebswitcher(WebSwitcherUrls $urls): Registrator
public function registerWebswitcher(WebSwitcherUrls $urls, ?DatabaseInfo $databaseInfo = null): Registrator
{
$this->addPanel(
__METHOD__,
function () use ($urls) {
return new WebSwitcher($urls, $this->smarty);
function () use ($urls, $databaseInfo) {
return new WebSwitcher($urls, $databaseInfo, $this->smarty);
}
);
......@@ -190,22 +209,4 @@ final class Registrator
return $this;
}
/**
* @param array|null $extraIps
* @return array|string[]
*/
private function getIps(?array $extraIps): array
{
$ips = [
'42@84.42.168.182',
'42@185.156.123.46',
'42@178.77.200.253',
];
if ($extraIps !== null) {
$ips = array_merge($ips, $extraIps);
}
return $ips;
}
}
......@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Praguebest\BarPanel;
use Praguebest\Tools\DatabaseInfo;
use Praguebest\Tools\GitParser;
use Praguebest\Tools\PBSParser;
use Praguebest\Tools\WebSwitcherUrls;
......@@ -17,21 +18,30 @@ final class WebSwitcher extends BaseBarPanel
*/
private $smarty;
public function __construct(WebSwitcherUrls $urls, Smarty $smarty)
public function __construct(WebSwitcherUrls $urls, ?DatabaseInfo $databaseInfo, Smarty $smarty)
{
$this->smarty = $smarty;
$this->smarty->assign('urls', $urls);
$databaseName = null;
$databaseLink = null;
if ($urls->isLocal()) {
$gitParser = new GitParser();
$branchName = $gitParser->getBranchName();
$branches = $gitParser->getBranches();
if ($databaseInfo !== null) {
$databaseName = $databaseInfo->getName();
$databaseLink = $databaseInfo->getLink();
}
}
$this->smarty->assign('branch', $branchName ?? null);
$this->smarty->assign('branches', $branches ?? []);
$this->smarty->assign('databaseName', $databaseName ?? null);
$this->smarty->assign('databaseLink', $databaseLink ?? null);
$this->smarty->assign('pbsParser', new PBSParser());
}
......
<?php
declare(strict_types=1);
namespace Praguebest\Tools;
final class DatabaseInfo
{
/**
* @var string
*/
private $name;
/**
* @var string|null
*/
private $link;
/**
* Database info to be shown on local server
* @param string $name Name of the database
* @param string|null $link Optional link to adminer to open the database like http://localhost/adminer.php?server=localhost&username=username&db=%s Must contain %s for sprint call with db name
*/
public function __construct(string $name, ?string $link = null)
{
$this->name = $name;
if ($link !== null) {
$this->link = sprintf($link, $this->name);
}
}
/**
* @return string|null
*/
public function getLink(): ?string
{
return $this->link;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
}
<?php
declare(strict_types=1);
namespace Praguebest\Tools;
final class DatabaseLink
{
/**
* @var string
*/
private $name;
/**
* @var string|null
*/
private $link;
public function __construct(string $name, ?string $link = null)
{
$this->name = $name;
$this->link = $link;
}
/**
* @return string|null
*/
public function getLink(): ?string
{
return $this->link;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
}
......@@ -117,6 +117,31 @@ final class Dumper
return Helpers::formatHtml('<span>%</span>', $file . ($line ? ":$line" : ''));
}
/**
* @param string $file
* @return string
*/
private static function localizePath(string $file): string
{
self::$projectPath = self::$projectPath ?? self::normalizePath(PersistentValue::getCurrentValue(self::PROJECT_PATH));
if (!self::$projectPath) {
return $file;
}
$byLocalDirectory = Strings::replace($file, '#' . preg_quote(self::getDirectory(), '#') . '#', self::$projectPath);
if ($byLocalDirectory === $file) {
return Strings::replace($file, '#(?<serverPath>.*?\.(\w+))\/#', self::$projectPath);
}
return $byLocalDirectory;
}
private static function normalizePath(string $path): string
{
return Strings::trim($path, Strings::TRIM_CHARACTERS . '/');
}
public static function getDirectory(): string
{
if (self::$rootDir === null) {
......@@ -206,29 +231,4 @@ final class Dumper
{
return ['Skipped'];
}
/**
* @param string $file
* @return string
*/
private static function localizePath(string $file): string
{
self::$projectPath = self::$projectPath ?? self::normalizePath(PersistentValue::getCurrentValue(self::PROJECT_PATH));
if (!self::$projectPath) {
return $file;
}
$byLocalDirectory = Strings::replace($file, '#' . preg_quote(self::getDirectory(), '#') . '#', self::$projectPath);
if ($byLocalDirectory === $file) {
return Strings::replace($file, '#(?<serverPath>.*?\.(\w+))\/#', self::$projectPath);
}
return $byLocalDirectory;
}
private static function normalizePath(string $path): string
{
return Strings::trim($path, Strings::TRIM_CHARACTERS . '/');
}
}
......@@ -104,6 +104,17 @@ final class ErrorFilesParser
return $message;
}
/**
* @param string $filename
* @return string
*/
private function getFilelink(string $filename): string
{
$link = "<a href='file://%s'>%s</a>";
return sprintf($link, rawurlencode($filename), basename($filename));
}
public function countCriticals(ArrayObject $errors): int
{
return $this->countErrorsByType($errors, [ILogger::CRITICAL, ILogger::EXCEPTION, ILogger::ERROR, ErrorFilesParser::UNKNOWN]);
......@@ -134,15 +145,4 @@ final class ErrorFilesParser
{
return $this->countErrorsByType($errors, [ILogger::DEBUG, ILogger::INFO]);
}
/**
* @param string $filename
* @return string
*/
private function getFilelink(string $filename): string
{
$link = "<a href='file://%s'>%s</a>";
return sprintf($link, rawurlencode($filename), basename($filename));
}
}
......@@ -6,7 +6,6 @@ use Nette\Utils\FileSystem;
final class GitParser
{
public function getLastCommitMessage(): ?string
{
$dir = Dumper::getDirectory();
......
......@@ -26,6 +26,11 @@ final class OnOff implements Setting
return $this->setting->getName();
}
public function getType(): string
{
return 'bool';
}
public function isOn(): bool
{
return (bool)$this->getValue() === true;
......@@ -35,9 +40,4 @@ final class OnOff implements Setting
{
return $this->setting->getValue();
}
public function getType(): string
{
return 'bool';
}
}
......@@ -12,5 +12,5 @@ interface Setting
public function getValue(): string;
public function getType():string;
public function getType(): string;
}
......@@ -3,6 +3,7 @@
namespace Praguebest\Tools\SmartyTrace;
use Smarty_Internal_Template;
use SmartyException;
class TraceableInternalTemplate extends Smarty_Internal_Template
{
......@@ -43,7 +44,7 @@ class TraceableInternalTemplate extends Smarty_Internal_Template
* @param bool $forceTplCache
* @param string|null $uid
* @param string|null $content_func
* @throws \SmartyException
* @throws SmartyException
*/
public function _subTemplateRender(
$template,
......
......@@ -54,7 +54,7 @@ class TraceableSmarty extends Smarty
/**
* @param array|string $tpl_var
* @param null $value
* @param mixed|null $value
* @param bool $nocache
*
* @return self
......
......@@ -42,7 +42,7 @@ final class WebSwitcherUrls
$normalized = Strings::replace(urldecode($current), '/' . preg_quote($host, '/') . '/', '%s', 1);
$this->local = sprintf($normalized, $local);
$this->local = Strings::replace(sprintf($normalized, $local), '|https|', 'http');
$this->testing = sprintf($normalized, $testing);
$this->live = sprintf($normalized, $live);
......
......@@ -2,7 +2,7 @@
<h1>Queries: {$count}, {($time * 1000)|number_format:2} ms</h1>
{include file="../filter.tpl"}
<input type="text" id="tracyBarSmartyFilter"
onkeyup="filterTable(this, document.getElementById('tracyBarDBProfileTable'),3)" placeholder="Filter">
onkeyup="filterTable(this, document.getElementById('tracyBarDBProfileTable'),3)" placeholder="Filter">
<div class="tracy-inner">
<div class="tracy-inner-container">
<table class="tracy-sortable" id="tracyBarDBProfileTable">
......
......@@ -18,6 +18,18 @@
<td>Live</td>
<td><a href="{$urls->getLive()}">{$urls->getLive()}</a></td>
</tr>
{if $databaseName}
<tr>
<td>Current<br>database</td>
<td style="vertical-align: middle;">
{if $databaseLink}
<a href="{$databaseLink}" target="_blank">{$databaseName}</a>
{else}
{$databaseName}
{/if}
</td>
</tr>
{/if}
{if $branch}
<tr>
<td>Branches</td>
......@@ -29,6 +41,7 @@
</td>
</tr>
{/if}
</table>
</div>
</div>
......
<span style="color: lightskyblue">//</span>
<span class="tracy-label">{$urls->getCurrent()|upper}</span>
<span style="color: #0075a2;font-weight: bold;">//</span>
<span class="tracy-label">{$urls->getCurrent()|ucfirst}</span>
{if $databaseName}
<span style="color: #121214;font-weight: bold;margin: 0 0 0 4px;">
<svg viewBox="0 0 2048 2048">
<path fill="#222" d="M1024 896q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0 768q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-384q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-1152q208 0 385 34.5t280 93.5 103 128v128q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-128q0-69 103-128t280-93.5 385-34.5z"/>
</svg>
</span>
<span class="tracy-label">{$databaseName}</span>
{/if}
{if $branch}
<span style="margin: 0 5px">
<svg viewBox="10 10 512 512">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment