1
0
mirror of https://github.com/dg/dibi.git synced 2025-09-02 18:42:36 +02:00

- added DibiProfiler (experimental)

- removed dibi::addHandler() & dibi::startLogger()
This commit is contained in:
David Grudl
2008-10-22 11:44:11 +00:00
parent 1e33b67e37
commit 32dd3969a3
8 changed files with 337 additions and 179 deletions

View File

@@ -72,6 +72,7 @@ require_once dirname(__FILE__) . '/libs/DibiTable.php';
require_once dirname(__FILE__) . '/libs/DibiDataSource.php';
require_once dirname(__FILE__) . '/libs/DibiFluent.php';
require_once dirname(__FILE__) . '/libs/DibiDatabaseInfo.php';
require_once dirname(__FILE__) . '/libs/DibiProfiler.php';
@@ -239,7 +240,7 @@ class dibi
* Retrieve active connection.
*
* @param string connection registy name
* @return object DibiConnection object.
* @return DibiConnection
* @throws DibiException
*/
public static function getConnection($name = NULL)
@@ -275,6 +276,18 @@ class dibi
/**
* Retrieve active connection profiler.
* @return IDibiProfiler
* @throws DibiException
*/
public static function getProfiler()
{
return self::getConnection()->getProfiler();
}
/********************* monostate for active connection ****************d*g**/
@@ -676,64 +689,6 @@ class dibi
/********************* event handling ****************d*g**/
/**
* Add new event handler.
*
* @param callback
* @return void
* @throws InvalidArgumentException
*/
public static function addHandler($callback)
{
if (!is_callable($callback)) {
throw new InvalidArgumentException("Invalid callback.");
}
self::$handlers[] = $callback;
}
/**
* Event notification (events: exception, connected, beforeQuery, afterQuery, begin, commit, rollback).
*
* @param DibiConnection
* @param string event name
* @param mixed
* @return void
*/
public static function notify(DibiConnection $connection = NULL, $event, $arg = NULL)
{
foreach (self::$handlers as $handler) {
call_user_func($handler, $connection, $event, $arg);
}
}
/**
* Enable profiler & logger.
*
* @param string filename
* @param bool log all queries?
* @return DibiProfiler
*/
public static function startLogger($file, $logQueries = FALSE)
{
require_once dirname(__FILE__) . '/libs/DibiLogger.php';
$logger = new DibiLogger($file);
$logger->logQueries = $logQueries;
self::addHandler(array($logger, 'handler'));
return $logger;
}
/********************* misc tools ****************d*g**/