1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-13 09:34:30 +02:00

now compatible with Debug / NDebug / Nette\Debug

This commit is contained in:
David Grudl
2010-08-25 01:15:59 +02:00
parent 310d43f404
commit 46a3b8a42c
6 changed files with 125 additions and 164 deletions

View File

@@ -1,44 +0,0 @@
<?php
/**
* Nette Framework
*
* @copyright Copyright (c) 2004, 2010 David Grudl
* @license http://nette.org/license Nette license
* @link http://nette.org
* @category Nette
* @package Nette
*/
/*namespace Nette;*/
/**
* Custom output for Nette\Debug.
*
* @copyright Copyright (c) 2004, 2010 David Grudl
* @package Nette
*/
interface IDebugPanel
{
/**
* Renders HTML code for custom tab.
* @return void
*/
function getTab();
/**
* Renders HTML code for custom panel.
* @return void
*/
function getPanel();
/**
* Returns panel ID.
* @return string
*/
function getId();
}

View File

@@ -32,64 +32,45 @@ if (version_compare(PHP_VERSION, '5.2.0', '<')) {
/**
* Compatibility with Nette
*/
if (!class_exists('NotImplementedException', FALSE)) {
/** @package exceptions */
if (interface_exists('Nette\\IDebugPanel', FALSE)) {
class_alias('Nette\\IDebugPanel', 'IDebugPanel');
} elseif (!interface_exists('IDebugPanel', FALSE)) {
interface IDebugPanel {}
}
if (!defined('NETTE')) {
/**#@+ @package exceptions */
class NotImplementedException extends LogicException {}
}
if (!class_exists('NotSupportedException', FALSE)) {
/** @package exceptions */
class NotSupportedException extends LogicException {}
}
if (!class_exists('MemberAccessException', FALSE)) {
/** @package exceptions */
class MemberAccessException extends LogicException {}
}
if (!class_exists('InvalidStateException', FALSE)) {
/** @package exceptions */
class InvalidStateException extends RuntimeException {}
}
if (!class_exists('IOException', FALSE)) {
/** @package exceptions */
class IOException extends RuntimeException {}
}
if (!class_exists('FileNotFoundException', FALSE)) {
/** @package exceptions */
class FileNotFoundException extends IOException {}
}
/**#@-*/
if (!class_exists('PcreException', FALSE)) {
/** @package exceptions */
class PcreException extends Exception {
public function __construct()
{
static $messages = array(
PREG_INTERNAL_ERROR => 'Internal error.',
PREG_BACKTRACK_LIMIT_ERROR => 'Backtrack limit was exhausted.',
PREG_RECURSION_LIMIT_ERROR => 'Recursion limit was exhausted.',
PREG_BAD_UTF8_ERROR => 'Malformed UTF-8 data.',
5 => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point.', // PREG_BAD_UTF8_OFFSET_ERROR
);
$code = preg_last_error();
parent::__construct(isset($messages[$code]) ? $messages[$code] : 'Unknown error.', $code);
}
}
}
if (!interface_exists(/*Nette\*/'IDebugPanel', FALSE)) {
require_once dirname(__FILE__) . '/Nette/IDebugPanel.php';
}
if (!class_exists('DateTime53', FALSE)) {
require_once dirname(__FILE__) . '/Nette/DateTime53.php';
}
/** @package exceptions */
class PcreException extends Exception {
public function __construct($message = '%msg.')
{
static $messages = array(
PREG_INTERNAL_ERROR => 'Internal error',
PREG_BACKTRACK_LIMIT_ERROR => 'Backtrack limit was exhausted',
PREG_RECURSION_LIMIT_ERROR => 'Recursion limit was exhausted',
PREG_BAD_UTF8_ERROR => 'Malformed UTF-8 data',
5 => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point', // PREG_BAD_UTF8_OFFSET_ERROR
);
$code = preg_last_error();
parent::__construct(str_replace('%msg', isset($messages[$code]) ? $messages[$code] : 'Unknown error', $message), $code);
}
}
/**
* @deprecated

View File

@@ -18,7 +18,7 @@
* @copyright Copyright (c) 2005, 2010 David Grudl
* @package dibi
*/
class DibiException extends Exception implements /*Nette\*/IDebugPanel
class DibiException extends Exception implements IDebugPanel
{
/** @var string */
private $sql;

View File

@@ -77,7 +77,7 @@ abstract class DibiObject
*/
final public function getReflection()
{
return new /*\*/ReflectionObject($this);
return new ReflectionObject($this);
}
@@ -94,15 +94,15 @@ abstract class DibiObject
$class = get_class($this);
if ($name === '') {
throw new /*\*/MemberAccessException("Call to class '$class' method without name.");
throw new MemberAccessException("Call to class '$class' method without name.");
}
// event functionality
if (preg_match('#^on[A-Z]#', $name)) {
$rp = new /*\*/ReflectionProperty($class, $name);
$rp = new ReflectionProperty($class, $name);
if ($rp->isPublic() && !$rp->isStatic()) {
$list = $this->$name;
if (is_array($list) || $list instanceof /*\*/Traversable) {
if (is_array($list) || $list instanceof Traversable) {
foreach ($list as $handler) {
/**/if (is_object($handler)) {
call_user_func_array(array($handler, '__invoke'), $args);
@@ -122,7 +122,7 @@ abstract class DibiObject
return call_user_func_array($cb, $args);
}
throw new /*\*/MemberAccessException("Call to undefined method $class::$name().");
throw new MemberAccessException("Call to undefined method $class::$name().");
}
@@ -137,7 +137,7 @@ abstract class DibiObject
public static function __callStatic($name, $args)
{
$class = get_called_class();
throw new /*\*/MemberAccessException("Call to undefined static method $class::$name().");
throw new MemberAccessException("Call to undefined static method $class::$name().");
}
@@ -215,7 +215,7 @@ abstract class DibiObject
$class = get_class($this);
if ($name === '') {
throw new /*\*/MemberAccessException("Cannot read a class '$class' property without name.");
throw new MemberAccessException("Cannot read a class '$class' property without name.");
}
// property getter support
@@ -236,7 +236,7 @@ abstract class DibiObject
}
$name = func_get_arg(0);
throw new /*\*/MemberAccessException("Cannot read an undeclared property $class::\$$name.");
throw new MemberAccessException("Cannot read an undeclared property $class::\$$name.");
}
@@ -253,7 +253,7 @@ abstract class DibiObject
$class = get_class($this);
if ($name === '') {
throw new /*\*/MemberAccessException("Cannot assign to a class '$class' property without name.");
throw new MemberAccessException("Cannot assign to a class '$class' property without name.");
}
// property setter support
@@ -266,12 +266,12 @@ abstract class DibiObject
} else {
$name = func_get_arg(0);
throw new /*\*/MemberAccessException("Cannot assign to a read-only property $class::\$$name.");
throw new MemberAccessException("Cannot assign to a read-only property $class::\$$name.");
}
}
$name = func_get_arg(0);
throw new /*\*/MemberAccessException("Cannot assign to an undeclared property $class::\$$name.");
throw new MemberAccessException("Cannot assign to an undeclared property $class::\$$name.");
}
@@ -298,7 +298,7 @@ abstract class DibiObject
public function __unset($name)
{
$class = get_class($this);
throw new /*\*/MemberAccessException("Cannot unset the property $class::\$$name.");
throw new MemberAccessException("Cannot unset the property $class::\$$name.");
}

View File

@@ -22,7 +22,7 @@
* @copyright Copyright (c) 2005, 2010 David Grudl
* @package dibi
*/
class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebugPanel
class DibiProfiler extends DibiObject implements IDibiProfiler, IDebugPanel
{
/** maximum number of rows */
static public $maxQueries = 30;
@@ -52,8 +52,12 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebug
public function __construct(array $config)
{
if (class_exists(/*Nette\*/'Debug', FALSE) && is_callable(/*Nette\*/'Debug::addPanel')) {
/*Nette\*/Debug::addPanel($this);
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);
}
$this->useFirebug = isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'FirePHP/');