diff --git a/dibi/Nette/IDebuggable.php b/dibi/Nette/IDebuggable.php index 8aa3a0c3..c1013dbd 100644 --- a/dibi/Nette/IDebuggable.php +++ b/dibi/Nette/IDebuggable.php @@ -23,6 +23,13 @@ /** * Custom output for Nette::Debug. */ -interface IDebuggable +interface Nette_IDebuggable { + + /** + * Returns custom panels. + * @return array + */ + function getPanels(); + } diff --git a/dibi/Nette/Object.php b/dibi/Nette/Object.php index 58bec3dc..7f2f3896 100644 --- a/dibi/Nette/Object.php +++ b/dibi/Nette/Object.php @@ -61,7 +61,7 @@ * @package Nette * @version $Revision$ $Date$ */ -abstract class NObject +abstract class Nette_Object { /** diff --git a/dibi/Nette/exceptions.php b/dibi/Nette/exceptions.php index 513c6ddf..c284c0f7 100644 --- a/dibi/Nette/exceptions.php +++ b/dibi/Nette/exceptions.php @@ -112,7 +112,7 @@ class DirectoryNotFoundException extends IOException /** - * User attempt to terminate the current script + * User attempt to terminate the current script. */ class AbortException extends RuntimeException { diff --git a/dibi/dibi.php b/dibi/dibi.php index faa4c36e..db425436 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -32,8 +32,8 @@ if (version_compare(PHP_VERSION, '5.1.0', '<')) { // nette libraries if (!class_exists('NotImplementedException', FALSE)) { require_once dirname(__FILE__) . '/Nette/exceptions.php'; } -if (!class_exists('NObject', FALSE)) { require_once dirname(__FILE__) . '/Nette/Object.php'; } -if (!interface_exists('IDebuggable', FALSE)) { require_once dirname(__FILE__) . '/Nette/IDebuggable.php'; } +if (!class_exists('Nette_Object', FALSE)) { require_once dirname(__FILE__) . '/Nette/Object.php'; } +if (!interface_exists('Nette_IDebuggable', FALSE)) { require_once dirname(__FILE__) . '/Nette/IDebuggable.php'; } // dibi libraries require_once dirname(__FILE__) . '/libs/interfaces.php'; @@ -154,6 +154,10 @@ class dibi + /********************* connections handling ****************d*g**/ + + + /** * Creates a new DibiConnection object and connects it to specified database. * @@ -164,7 +168,11 @@ class dibi */ public static function connect($config = array(), $name = 0) { - if (is_array($config) || $config instanceof IMap) { + if (class_exists('Nette_Debug', FALSE) && Nette_Debug::isEnabled()) { + Nette_Debug::addColophon(array(__CLASS__, 'getColophon')); + } + + if (is_array($config) || $config instanceof Nette_Collections_IMap) { $config['name'] = $name; } else { $config .= '&name=' . urlencode($name); @@ -238,6 +246,10 @@ class dibi + /********************* monostate for active connection ****************d*g**/ + + + /** * Generates and executes SQL query - Monostate for DibiConnection::query(). * @@ -413,6 +425,10 @@ class dibi + /********************* data types ****************d*g**/ + + + /** * Pseudotype for timestamp representation. * @@ -448,6 +464,10 @@ class dibi + /********************* substitutions ****************d*g**/ + + + /** * Create a new substitution pair for indentifiers. * @@ -491,6 +511,10 @@ class dibi + /********************* event handling ****************d*g**/ + + + /** * Add new event handler. * @@ -543,6 +567,10 @@ class dibi + /********************* misc tools ****************d*g**/ + + + /** * Prints out a syntax highlighted version of the SQL command or DibiResult. * @@ -604,4 +632,17 @@ class dibi } + + /** + * Returns brief descriptions. + * @return array + */ + public static function getColophon() + { + return array( + 'dibi version: ' . dibi::VERSION, + 'Number or queries: ' . dibi::$numOfQueries . (dibi::$totalTime === NULL ? '' : ' (elapsed time: ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms)'), + ); + } + } diff --git a/dibi/drivers/mssql.php b/dibi/drivers/mssql.php index d48b9609..595c2ffc 100644 --- a/dibi/drivers/mssql.php +++ b/dibi/drivers/mssql.php @@ -34,7 +34,7 @@ * @package dibi * @version $Revision$ $Date$ */ -class DibiMsSqlDriver extends NObject implements IDibiDriver +class DibiMsSqlDriver extends Nette_Object implements IDibiDriver { /** diff --git a/dibi/drivers/mysql.php b/dibi/drivers/mysql.php index 7d3731ca..8dd0e7f7 100644 --- a/dibi/drivers/mysql.php +++ b/dibi/drivers/mysql.php @@ -40,7 +40,7 @@ * @package dibi * @version $Revision$ $Date$ */ -class DibiMySqlDriver extends NObject implements IDibiDriver +class DibiMySqlDriver extends Nette_Object implements IDibiDriver { /** diff --git a/dibi/drivers/mysqli.php b/dibi/drivers/mysqli.php index a1fa05e8..36c0962c 100644 --- a/dibi/drivers/mysqli.php +++ b/dibi/drivers/mysqli.php @@ -40,7 +40,7 @@ * @package dibi * @version $Revision$ $Date$ */ -class DibiMySqliDriver extends NObject implements IDibiDriver +class DibiMySqliDriver extends Nette_Object implements IDibiDriver { /** diff --git a/dibi/drivers/odbc.php b/dibi/drivers/odbc.php index b98a84c0..04ea55be 100644 --- a/dibi/drivers/odbc.php +++ b/dibi/drivers/odbc.php @@ -33,7 +33,7 @@ * @package dibi * @version $Revision$ $Date$ */ -class DibiOdbcDriver extends NObject implements IDibiDriver +class DibiOdbcDriver extends Nette_Object implements IDibiDriver { /** diff --git a/dibi/drivers/oracle.php b/dibi/drivers/oracle.php index 46a355b1..06ba6247 100644 --- a/dibi/drivers/oracle.php +++ b/dibi/drivers/oracle.php @@ -33,7 +33,7 @@ * @package dibi * @version $Revision$ $Date$ */ -class DibiOracleDriver extends NObject implements IDibiDriver +class DibiOracleDriver extends Nette_Object implements IDibiDriver { /** diff --git a/dibi/drivers/pdo.php b/dibi/drivers/pdo.php index 57a98a5c..e286e055 100644 --- a/dibi/drivers/pdo.php +++ b/dibi/drivers/pdo.php @@ -33,7 +33,7 @@ * @package dibi * @version $Revision$ $Date$ */ -class DibiPdoDriver extends NObject implements IDibiDriver +class DibiPdoDriver extends Nette_Object implements IDibiDriver { /** diff --git a/dibi/drivers/postgre.php b/dibi/drivers/postgre.php index eec53b6f..e04c612c 100644 --- a/dibi/drivers/postgre.php +++ b/dibi/drivers/postgre.php @@ -34,7 +34,7 @@ * @package dibi * @version $Revision$ $Date$ */ -class DibiPostgreDriver extends NObject implements IDibiDriver +class DibiPostgreDriver extends Nette_Object implements IDibiDriver { /** diff --git a/dibi/drivers/sqlite.php b/dibi/drivers/sqlite.php index 4286441c..f14d1527 100644 --- a/dibi/drivers/sqlite.php +++ b/dibi/drivers/sqlite.php @@ -34,7 +34,7 @@ * @package dibi * @version $Revision$ $Date$ */ -class DibiSqliteDriver extends NObject implements IDibiDriver +class DibiSqliteDriver extends Nette_Object implements IDibiDriver { /** diff --git a/dibi/libs/DibiConnection.php b/dibi/libs/DibiConnection.php index c1033e52..1a78b93c 100644 --- a/dibi/libs/DibiConnection.php +++ b/dibi/libs/DibiConnection.php @@ -27,7 +27,7 @@ * @package dibi * @version $Revision$ $Date$ */ -class DibiConnection extends NObject +class DibiConnection extends Nette_Object { /** * Current connection configuration. @@ -58,7 +58,7 @@ class DibiConnection extends NObject /** * Creates object and (optionally) connects to a database. * - * @param array|string|IMap connection parameters + * @param array|string|Nette_Collections_IMap connection parameters * @throws DibiException */ public function __construct($config) @@ -67,7 +67,7 @@ class DibiConnection extends NObject if (is_string($config)) { parse_str($config, $config); - } elseif ($config instanceof IMap) { + } elseif ($config instanceof Nette_Collections_IMap) { $config = $config->toArray(); } diff --git a/dibi/libs/DibiDataSource.php b/dibi/libs/DibiDataSource.php index 64c0e69d..a325f11f 100644 --- a/dibi/libs/DibiDataSource.php +++ b/dibi/libs/DibiDataSource.php @@ -27,7 +27,7 @@ * @package dibi * @version $Revision$ $Date$ */ -class DibiDataSource extends NObject implements IDataSource +class DibiDataSource extends Nette_Object implements IDataSource { /** @var DibiConnection */ private $connection; diff --git a/dibi/libs/DibiException.php b/dibi/libs/DibiException.php index 313f605f..a3c494e6 100644 --- a/dibi/libs/DibiException.php +++ b/dibi/libs/DibiException.php @@ -42,7 +42,7 @@ class DibiException extends Exception * @package dibi * @version $Revision$ $Date$ */ -class DibiDriverException extends DibiException implements IDebuggable +class DibiDriverException extends DibiException implements Nette_IDebuggable { /** @var string */ private static $errorMsg; @@ -87,6 +87,27 @@ class DibiDriverException extends DibiException implements IDebuggable + /********************* interface Nette_IDebuggable ****************d*g**/ + + + /** + * Returns custom panels. + * @return array + */ + public function getPanels() + { + $panels = array(); + if ($this->sql !== NULL) { + $panels['SQL'] = array( + 'expanded' => TRUE, + 'content' => dibi::dump($this->sql, TRUE), + ); + } + return $panels; + } + + + /********************* error catching ****************d*g**/ diff --git a/dibi/libs/DibiLogger.php b/dibi/libs/DibiLogger.php index 5181362b..b4eaae5d 100644 --- a/dibi/libs/DibiLogger.php +++ b/dibi/libs/DibiLogger.php @@ -27,7 +27,7 @@ * @package dibi * @version $Revision$ $Date$ */ -final class DibiLogger extends NObject +final class DibiLogger extends Nette_Object { /** @var string Name of the file where SQL errors should be logged */ private $file; diff --git a/dibi/libs/DibiResult.php b/dibi/libs/DibiResult.php index 2521b247..5afd76d9 100644 --- a/dibi/libs/DibiResult.php +++ b/dibi/libs/DibiResult.php @@ -41,7 +41,7 @@ * @package dibi * @version $Revision$ $Date$ */ -class DibiResult extends NObject implements IDataSource +class DibiResult extends Nette_Object implements IDataSource { /** * IDibiDriver. @@ -240,7 +240,7 @@ class DibiResult extends NObject implements IDataSource if ($this->xlat !== NULL) { foreach ($this->xlat as $col => $type) { if (isset($row[$col])) { - $row[$col] = $this->convert($row[$col], $type); + $row[$col] = $this->convert($row[$col], $type[0], $type[1]); } } } @@ -269,7 +269,8 @@ class DibiResult extends NObject implements IDataSource // types-converting? $key = key($row); if (isset($this->xlat[$key])) { - return $this->convert($value, $this->xlat[$key]); + $type = $this->xlat[$key]; + return $this->convert($value, $type[0], $type[1]); } return $value; @@ -447,14 +448,9 @@ class DibiResult extends NObject implements IDataSource - final public function setType($col, $type = NULL) + final public function setType($col, $type = NULL, $format = NULL) { - if (is_array($col)) { - $this->xlat = $col; - - } else { - $this->xlat[$col] = $type; - } + $this->xlat[$col] = array($type, $format); } @@ -466,7 +462,7 @@ class DibiResult extends NObject implements IDataSource - final public function convert($value, $type) + final public function convert($value, $type, $format = NULL) { if ($value === NULL || $value === FALSE) { return $value; @@ -478,7 +474,7 @@ class DibiResult extends NObject implements IDataSource } if ($type === dibi::FIELD_DATE || $type === dibi::FIELD_DATETIME) { - return strtotime($value); + return $format === NULL ? strtotime($value) : date($format, strtotime($value)); } if ($type === dibi::FIELD_BOOL) { diff --git a/dibi/libs/DibiTable.php b/dibi/libs/DibiTable.php index 79517500..19ed24d5 100644 --- a/dibi/libs/DibiTable.php +++ b/dibi/libs/DibiTable.php @@ -26,7 +26,7 @@ * @package dibi * @version $Revision$ $Date$ */ -abstract class DibiTable extends NObject +abstract class DibiTable extends Nette_Object { /** @var string primary key mask */ public static $primaryMask = 'id'; diff --git a/dibi/libs/DibiTranslator.php b/dibi/libs/DibiTranslator.php index 3af6eb35..ce76f474 100644 --- a/dibi/libs/DibiTranslator.php +++ b/dibi/libs/DibiTranslator.php @@ -27,7 +27,7 @@ * @package dibi * @version $Revision$ $Date$ */ -final class DibiTranslator extends NObject +final class DibiTranslator extends Nette_Object { /** @var string */ public $sql; diff --git a/dibi/libs/DibiVariable.php b/dibi/libs/DibiVariable.php index abd85d82..469d9756 100644 --- a/dibi/libs/DibiVariable.php +++ b/dibi/libs/DibiVariable.php @@ -23,7 +23,7 @@ * Default implemenation of IDibiVariable. * @package dibi */ -class DibiVariable extends NObject implements IDibiVariable +class DibiVariable extends Nette_Object implements IDibiVariable { /** @var mixed */ public $value; diff --git a/examples/metatypes.php b/examples/metatypes.php index 8f802d21..878db729 100644 --- a/examples/metatypes.php +++ b/examples/metatypes.php @@ -15,5 +15,7 @@ $res = dibi::query('SELECT * FROM [customers]'); // auto-convert this column to integer $res->setType('customer_id', Dibi::FIELD_INTEGER); +$res->setType('added', Dibi::FIELD_DATETIME, 'H:i j.n.Y'); + $row = $res->fetch(); var_dump($row); diff --git a/examples/nette-debug.php b/examples/nette-debug.php new file mode 100644 index 00000000..e50a515e --- /dev/null +++ b/examples/nette-debug.php @@ -0,0 +1,19 @@ +