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

basic cleaning

parent a26417b0
......@@ -9,7 +9,6 @@
"email": "pospisil@praguebest.cz"
}
],
"version": "0.0.1",
"autoload": {
"psr-4": {
"Praguebest\\": "src/"
......@@ -18,9 +17,7 @@
"require": {
"php": "^7.1",
"tracy/tracy": "^2.7",
"nette/utils": "3.0.*"
},
"require-dev": {
"nette/utils": "^3.0",
"smarty/smarty": "^3.1"
}
}
......@@ -4,25 +4,105 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "e96a9c74d2024f4a354efec51ec8a24b",
"content-hash": "81b69c965ce3eb2238488bb19d81133c",
"packages": [
{
"name": "nette/utils",
"version": "v3.0.2",
"source": {
"type": "git",
"url": "https://github.com/nette/utils.git",
"reference": "c133e18c922dcf3ad07673077d92d92cef25a148"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/utils/zipball/c133e18c922dcf3ad07673077d92d92cef25a148",
"reference": "c133e18c922dcf3ad07673077d92d92cef25a148",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"require-dev": {
"nette/tester": "~2.0",
"tracy/tracy": "^2.3"
},
"suggest": {
"ext-gd": "to use Image",
"ext-iconv": "to use Strings::webalize() and toAscii()",
"ext-intl": "to use Strings::webalize(), toAscii(), normalize() and compare()",
"ext-json": "to use Nette\\Utils\\Json",
"ext-mbstring": "to use Strings::lower() etc...",
"ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()",
"ext-xml": "to use Strings::length() etc. when mbstring is not available"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause",
"GPL-2.0",
"GPL-3.0"
],
"authors": [
{
"name": "David Grudl",
"homepage": "https://davidgrudl.com"
},
{
"name": "Nette Community",
"homepage": "https://nette.org/contributors"
}
],
"description": "🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.",
"homepage": "https://nette.org",
"keywords": [
"array",
"core",
"datetime",
"images",
"json",
"nette",
"paginator",
"password",
"slugify",
"string",
"unicode",
"utf-8",
"utility",
"validation"
],
"time": "2019-10-21T20:40:16+00:00"
},
{
"name": "smarty/smarty",
"version": "v3.1.33",
"version": "v3.1.34",
"source": {
"type": "git",
"url": "https://github.com/smarty-php/smarty.git",
"reference": "dd55b23121e55a3b4f1af90a707a6c4e5969530f"
"reference": "c9f0de05f41b9e52798b268ab1e625fac3b8578c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/smarty-php/smarty/zipball/dd55b23121e55a3b4f1af90a707a6c4e5969530f",
"reference": "dd55b23121e55a3b4f1af90a707a6c4e5969530f",
"url": "https://api.github.com/repos/smarty-php/smarty/zipball/c9f0de05f41b9e52798b268ab1e625fac3b8578c",
"reference": "c9f0de05f41b9e52798b268ab1e625fac3b8578c",
"shasum": ""
},
"require": {
"php": ">=5.2"
},
"require-dev": {
"phpunit/phpunit": "6.4.1"
},
"type": "library",
"extra": {
"branch-alias": {
......@@ -30,8 +110,8 @@
}
},
"autoload": {
"files": [
"libs/bootstrap.php"
"classmap": [
"libs/"
]
},
"notification-url": "https://packagist.org/downloads/",
......@@ -57,20 +137,20 @@
"keywords": [
"templating"
],
"time": "2018-09-12T20:54:16+00:00"
"time": "2019-02-28T06:42:20+00:00"
},
{
"name": "tracy/tracy",
"version": "v2.6.4",
"version": "v2.7.1",
"source": {
"type": "git",
"url": "https://github.com/nette/tracy.git",
"reference": "cad2ec2c40cee828ce5538a4bc5bbde7045a7c1b"
"reference": "16691cf8b609b238a9a3596ee2878183a91b6446"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/tracy/zipball/cad2ec2c40cee828ce5538a4bc5bbde7045a7c1b",
"reference": "cad2ec2c40cee828ce5538a4bc5bbde7045a7c1b",
"url": "https://api.github.com/repos/nette/tracy/zipball/16691cf8b609b238a9a3596ee2878183a91b6446",
"reference": "16691cf8b609b238a9a3596ee2878183a91b6446",
"shasum": ""
},
"require": {
......@@ -78,10 +158,13 @@
"ext-session": "*",
"php": ">=7.1"
},
"conflict": {
"nette/di": "<3.0"
},
"require-dev": {
"nette/di": "^2.4 || ~3.0.0",
"nette/di": "^3.0",
"nette/tester": "^2.2",
"nette/utils": "^2.4 || ^3.0",
"nette/utils": "^3.0",
"psr/log": "^1.0"
},
"suggest": {
......@@ -90,7 +173,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.6-dev"
"dev-master": "2.7-dev"
}
},
"autoload": {
......@@ -124,7 +207,7 @@
"nette",
"profiler"
],
"time": "2019-07-16T14:23:55+00:00"
"time": "2019-11-02T20:12:14+00:00"
}
],
"packages-dev": [],
......
......@@ -30,27 +30,27 @@ final class DBProfiler implements Tracy\IBarPanel
}
/**
* Renders HTML code for custom tab.
* Renders HTML code for custom panel.
* @return string
* @throws SmartyException
*/
public function getTab(): string
public function getPanel(): string
{
$this->assignSmarty();
return $this->smarty->fetch(dirname(__DIR__) . '/templates/database/tab.tpl');
return $this->smarty->fetch(dirname(__DIR__) . '/templates/database/dbProfiler.tpl');
}
/**
* Renders HTML code for custom panel.
* Renders HTML code for custom tab.
* @return string
* @throws SmartyException
*/
public function getPanel(): string
public function getTab(): string
{
$this->assignSmarty();
return $this->smarty->fetch(dirname(__DIR__) . '/templates/database/dbProfiler.tpl');
return $this->smarty->fetch(dirname(__DIR__) . '/templates/database/tab.tpl');
}
private function assignSmarty(): void
......
......@@ -32,27 +32,27 @@ final class SmartyBarPanel implements Tracy\IBarPanel
}
/**
* Renders HTML code for custom tab.
* Renders HTML code for custom panel.
* @return string
* @throws SmartyException
*/
public function getTab(): string
public function getPanel(): string
{
$this->assignSmarty();
return $this->smarty->fetch(dirname(__DIR__) . '/templates/smarty/tab.tpl');
return $this->smarty->fetch(dirname(__DIR__) . '/templates/smarty/smartyVars.tpl');
}
/**
* Renders HTML code for custom panel.
* Renders HTML code for custom tab.
* @return string
* @throws SmartyException
*/
public function getPanel(): string
public function getTab(): string
{
$this->assignSmarty();
return $this->smarty->fetch(dirname(__DIR__) . '/templates/smarty/smartyVars.tpl');
return $this->smarty->fetch(dirname(__DIR__) . '/templates/smarty/tab.tpl');
}
private function assignSmarty(): void
......
......@@ -24,22 +24,22 @@ final class WebSwitcher implements Tracy\IBarPanel
}
/**
* Renders HTML code for custom tab.
* Renders HTML code for custom panel.
* @return string
* @throws SmartyException
*/
public function getTab(): string
public function getPanel(): string
{
return $this->smarty->fetch(dirname(__DIR__) . '/templates/webswitcher/tab.tpl');
return $this->smarty->fetch(dirname(__DIR__) . '/templates/webswitcher/contexts.tpl');
}
/**
* Renders HTML code for custom panel.
* Renders HTML code for custom tab.
* @return string
* @throws SmartyException
*/
public function getPanel(): string
public function getTab(): string
{
return $this->smarty->fetch(dirname(__DIR__) . '/templates/webswitcher/contexts.tpl');
return $this->smarty->fetch(dirname(__DIR__) . '/templates/webswitcher/tab.tpl');
}
}
......@@ -2,21 +2,21 @@
namespace Praguebest\Tools;
use PDOStatement;
use Praguebest\BarPanel\Helper;
final class DBProfiler
{
private const PROFILE_DB = 'profileDB';
/** @var DBProfiler */
private static $instance;
/** @var PublisherQueryFormatter */
private $publisherQueryFormatter;
private $queriesProfiler = [];
/**
* @var bool
*/
private $profile = false;
/**
* @var float
*/
......@@ -26,21 +26,11 @@ final class DBProfiler
*/
private $totalCount = 0;
/** @var DBProfiler */
private static $instance;
private function __construct()
{
$this->initProfiling();
}
public static function getInstance(): self
{
self::$instance = self::$instance ?? new self();
return self::$instance;
}
private function initProfiling(): void
{
if (session_status() !== PHP_SESSION_ACTIVE) {
......@@ -57,7 +47,26 @@ final class DBProfiler
}
}
public function profilePublisher(\PDOStatement $statement, ?array $placeholders, ?array $extraParams): bool
private function getFromSession(): bool
{
$profileDB = $_SESSION[DBProfiler::PROFILE_DB] ?? false;
return (bool)$profileDB;
}
private function setToSession(bool $value): void
{
$_SESSION[DBProfiler::PROFILE_DB] = $value;
}
public static function getInstance(): self
{
self::$instance = self::$instance ?? new self();
return self::$instance;
}
public function profilePublisher(PDOStatement $statement, ?array $placeholders, ?array $extraParams): bool
{
$start = $this->timer();
......@@ -71,6 +80,18 @@ final class DBProfiler
return $result;
}
public function timer(): float
{
return round(microtime(true), 5);
}
public function getPublisherQueryFormatter(): PublisherQueryFormatter
{
$this->publisherQueryFormatter = $this->publisherQueryFormatter ?? new PublisherQueryFormatter();
return $this->publisherQueryFormatter;
}
public function profile(string $sql, float $tookTime, ?array $backtrace = null): void
{
if ($this->profile === null || $this->profile === false) {
......@@ -87,32 +108,6 @@ final class DBProfiler
}
}
public function returnProfiling(string $sortBy = 'time'): array
{
return $this->arrayOrderby($this->queriesProfiler, $sortBy, SORT_DESC);
}
private function arrayOrderby(): array
{
$args = func_get_args();
$data = array_shift($args);
foreach ($args as $n => $field) {
if (is_string($field)) {
$tmp = array_map(
static function ($row) use ($field) {
return $row[$field];
},
$data
);
$args[$n] = $tmp;
}
}
$args[] = &$data;
array_multisort(...$args);
return array_pop($args);
}
private function setQueryProfileResults(string $hash, string $sql, float $time, array $backtrace): void
{
if (isset($this->queriesProfiler[$hash])) {
......@@ -180,16 +175,30 @@ final class DBProfiler
return "<span class='dump'>${sql}</span>";
}
private function setToSession(bool $value): void
public function returnProfiling(string $sortBy = 'time'): array
{
$_SESSION[DBProfiler::PROFILE_DB] = $value;
return $this->arrayOrderby($this->queriesProfiler, $sortBy, SORT_DESC);
}
private function getFromSession(): bool
private function arrayOrderby(): array
{
$profileDB = $_SESSION[DBProfiler::PROFILE_DB] ?? false;
$args = func_get_args();
$data = array_shift($args);
foreach ($args as $n => $field) {
if (is_string($field)) {
$tmp = array_map(
static function ($row) use ($field) {
return $row[$field];
},
$data
);
$args[$n] = $tmp;
}
}
$args[] = &$data;
array_multisort(...$args);
return (bool)$profileDB;
return array_pop($args);
}
public function getTotalCount(): int
......@@ -206,16 +215,4 @@ final class DBProfiler
{
return $this->profile;
}
public function getPublisherQueryFormatter(): PublisherQueryFormatter
{
$this->publisherQueryFormatter = $this->publisherQueryFormatter ?? new PublisherQueryFormatter();
return $this->publisherQueryFormatter;
}
public function timer(): float
{
return round(microtime(true), 5);
}
}
......@@ -2,6 +2,8 @@
namespace Praguebest\Tools;
use SqlPrepareIn;
final class PublisherQueryFormatter
{
public function debugQuery(string $sql, ?array $placeholders, ?array $extraParams): string
......@@ -39,8 +41,8 @@ final class PublisherQueryFormatter
foreach ($keys as $key => $value) {
$param = $this->_debugGetParam($value);
if ($param instanceof \SqlPrepareIn) {
if ($param instanceof \SqlPrepareIn && is_array($param->getData())) {
if ($param instanceof SqlPrepareIn) {
if ($param instanceof SqlPrepareIn && is_array($param->getData())) {
$key = $param->getSql();
$param = implode(',', $param->getData());
}
......
......@@ -3,8 +3,9 @@
namespace Praguebest\Tools;
use Praguebest\BarPanel\Registrator;
use Smarty;
class TraceableSmarty extends \Smarty
class TraceableSmarty extends Smarty
{
/** @var array */
private $backtraces;
......@@ -31,11 +32,6 @@ class TraceableSmarty extends \Smarty
return $this;
}
public function getBacktraces(): array
{
return $this->backtraces;
}
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
{
parent::display($template, $cache_id, $compile_id, $parent);
......@@ -43,4 +39,9 @@ class TraceableSmarty extends \Smarty
Registrator::getInstance($this->getCompileDir(), $this->getCacheDir())->registerSmarty($this);
}
public function getBacktraces(): array
{
return $this->backtraces;
}
}
......@@ -16,7 +16,7 @@
{if isset($smartyBacktrace[$key])}
<small>
{$smartyBacktrace[$key]['first']['loc'] nofilter} : {$smartyBacktrace[$key]['first']['name'] nofilter}
<a class="tracy-toggle tracy-collapsed" data-tracy-ref="^tr .nette-DbConnectionPanel-trace">more</a>
<a class="tracy-toggle tracy-collapsed" data-tracy-ref="^tr .nette-DbConnectionPanel-trace">more</a>
</small>
<table class="tracy-collapsed nette-DbConnectionPanel-trace">
{foreach $smartyBacktrace[$key]['lines'] as $line}
......
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