1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-08 07:06:52 +02:00

updated for Nette 2.0 beta

This commit is contained in:
David Grudl
2011-04-21 01:52:02 +02:00
parent 8a899c7ddb
commit 0de947883b
7 changed files with 358 additions and 364 deletions

View File

@@ -29,7 +29,7 @@ if (!defined('NETTE')) {
*
* @author David Grudl
*/
class DibiException extends Exception implements IDebugPanel
class DibiException extends Exception
{
/** @var string */
private $sql;
@@ -68,43 +68,6 @@ class DibiException extends Exception implements IDebugPanel
return parent::__toString() . ($this->sql ? "\nSQL: " . $this->sql : '');
}
/********************* interface Nette\IDebugPanel ****************d*g**/
/**
* Returns HTML code for custom tab.
* @return mixed
*/
public function getTab()
{
return 'SQL';
}
/**
* Returns HTML code for custom panel.
* @return mixed
*/
public function getPanel()
{
return $this->sql ? dibi::dump($this->sql, TRUE) : NULL;
}
/**
* Returns panel ID.
* @return string
*/
public function getId()
{
return __CLASS__;
}
}

View File

@@ -22,7 +22,7 @@
*
* @author David Grudl
*/
class DibiProfiler extends DibiObject implements IDibiProfiler, IDebugPanel
class DibiProfiler extends DibiObject implements IDibiProfiler, IBarPanel
{
/** maximum number of rows */
static public $maxQueries = 30;
@@ -52,12 +52,17 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, IDebugPanel
public function __construct(array $config)
{
if (is_callable('Nette\Debug::addPanel')) {
call_user_func('Nette\Debug::addPanel', $this);
} elseif (is_callable('NDebug::addPanel')) {
NDebug::addPanel($this);
} elseif (is_callable('Debug::addPanel')) {
Debug::addPanel($this);
if (is_callable('Nette\Diagnostics\Debugger::enable')) {
eval('$tmp = Nette\Diagnostics\Debugger::$bar;');
$tmp->addPanel($this);
eval('$tmp = Nette\Diagnostics\Debugger::$blueScreen;');
$tmp->addPanel(array($this, 'renderException'), __CLASS__);
} elseif (is_callable('NDebugger::enable')) {
NDebugger::$bar->addPanel($this);
NDebugger::$blueScreen->addPanel(array($this, 'renderException'), __CLASS__);
} elseif (is_callable('Debugger::enable')) {
Debugger::$bar->addPanel($this);
Debugger::$blueScreen->addPanel(array($this, 'renderException'), __CLASS__);
}
$this->useFirebug = isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'FirePHP/');
@@ -77,6 +82,18 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, IDebugPanel
public function renderException($e)
{
if ($e instanceof DibiException && $e->getSql()) {
return array(
'tab' => 'SQL',
'panel' => dibi::dump($e->getSql(), TRUE),
);
}
}
/**
* @param string filename
* @return DibiProfiler provides a fluent interface
@@ -242,7 +259,7 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, IDebugPanel
/********************* interface Nette\IDebugPanel ****************d*g**/
/********************* interface Nette\Diagnostics\IBarPanel ****************d*g**/
@@ -308,15 +325,4 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, IDebugPanel
</div>';
}
/**
* Returns panel ID.
* @return string
*/
public function getId()
{
return get_class($this);
}
}