fixed critical bug in static definition classes
updated debugging class to new doctrine SQLLogger interface
This commit is contained in:
parent
e0dd10bf7d
commit
863b9d2d72
2 changed files with 24 additions and 31 deletions
|
@ -23,6 +23,8 @@
|
|||
|
||||
namespace Volkszaehler\Util;
|
||||
|
||||
use Doctrine\ORM;
|
||||
|
||||
use Doctrine\DBAL\Logging;
|
||||
|
||||
/**
|
||||
|
@ -31,11 +33,11 @@ use Doctrine\DBAL\Logging;
|
|||
* @package util
|
||||
* @author Steffen Vogel <info@steffenvogel.de>
|
||||
*/
|
||||
class Debug implements Logging\SQLLogger {
|
||||
class Debug {
|
||||
protected static $instance = NULL;
|
||||
|
||||
protected $queries = array();
|
||||
protected $messages = array();
|
||||
protected $sqlLogger;
|
||||
|
||||
/** @var float holds timestamp of initialization, used later to return time of execution */
|
||||
protected $started;
|
||||
|
@ -48,12 +50,17 @@ class Debug implements Logging\SQLLogger {
|
|||
*
|
||||
* @param integer $level the debug level
|
||||
*/
|
||||
public function __construct($level) {
|
||||
public function __construct($level, ORM\EntityManager $em) {
|
||||
// taking timestamp to stop execution time
|
||||
$this->created = microtime(TRUE);
|
||||
|
||||
// saving debug level
|
||||
$this->level = $level;
|
||||
|
||||
// starting logging of sql queries
|
||||
$this->sqlLogger = new Logging\DebugStack();
|
||||
$em->getConnection()->getConfiguration()->setSQLLogger($this->sqlLogger);
|
||||
|
||||
if (isset(self::$instance)) {
|
||||
throw new \Exception('debugging has already been started. please use the static functions!');
|
||||
}
|
||||
|
@ -66,16 +73,6 @@ class Debug implements Logging\SQLLogger {
|
|||
assert_options(ASSERT_CALLBACK, array($this, 'assertHandler'));
|
||||
}
|
||||
|
||||
/**
|
||||
* interface for Doctrine's DBAL SQLLogger
|
||||
*
|
||||
* @param string $sql the sql query
|
||||
* @param array $parameters optional parameters for prepared queries
|
||||
*/
|
||||
function logSQL($sql, array $parameters = NULL, $executionMS = null) {
|
||||
$this->queries[] = array('sql' => $sql, 'parameters' => $parameters, 'execution' => round($executionMS, 5));
|
||||
}
|
||||
|
||||
/*
|
||||
* logs messages to the debug stack including file, lineno, args and a stacktrace
|
||||
*
|
||||
|
@ -85,14 +82,15 @@ class Debug implements Logging\SQLLogger {
|
|||
static public function log($message) {
|
||||
if (isset(self::$instance)) {
|
||||
$trace = debug_backtrace();
|
||||
$info = $trace[0];
|
||||
|
||||
self::$instance->messages[] = array(
|
||||
'message' => $message,
|
||||
'file' => $trace[0]['file'],
|
||||
'line' => $trace[0]['line'],
|
||||
'file' => $info['file'],
|
||||
'line' => $info['line'],
|
||||
'time' => date('r'),
|
||||
'args' => array_slice($trace[0]['args'], 1),
|
||||
'trace' => $trace
|
||||
'args' => array_slice($info['args'], 1),
|
||||
'trace' => array_slice($trace, 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -123,7 +121,7 @@ class Debug implements Logging\SQLLogger {
|
|||
'file' => $info['file'],
|
||||
'line' => $info['line'],
|
||||
'time' => date('r'),
|
||||
'trace' => array_slice($trace, 2)
|
||||
'trace' => array_slice($trace, 3)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -141,7 +139,7 @@ class Debug implements Logging\SQLLogger {
|
|||
/**
|
||||
* @return 2 dimensional array with sql queries and parameters
|
||||
*/
|
||||
public function getQueries() { return $this->queries; }
|
||||
public function getQueries() { return $this->sqlLogger->queries; }
|
||||
|
||||
/**
|
||||
* @return 2 dimensional array with messages
|
||||
|
|
|
@ -28,9 +28,6 @@ namespace Volkszaehler\Util;
|
|||
* @package util
|
||||
*/
|
||||
abstract class Definition {
|
||||
/** @var array cached json definitions */
|
||||
protected static $definitions = NULL;
|
||||
|
||||
/** @var string discriminator for database column */
|
||||
protected $name;
|
||||
|
||||
|
@ -64,11 +61,11 @@ abstract class Definition {
|
|||
* @return Util\Definition
|
||||
*/
|
||||
public static function get($name) {
|
||||
if (!self::exists($name)) {
|
||||
if (!static::exists($name)) {
|
||||
throw new \Exception('unknown definition');
|
||||
}
|
||||
|
||||
return self::$definitions[$name];
|
||||
return static::$definitions[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,13 +73,11 @@ abstract class Definition {
|
|||
* @param string $name
|
||||
*/
|
||||
public static function exists($name) {
|
||||
if (is_null(self::$definitions)) {
|
||||
self::load();
|
||||
if (is_null(static::$definitions)) {
|
||||
static::load();
|
||||
}
|
||||
|
||||
Debug::log('definitions', self::$definitions);
|
||||
|
||||
return isset(self::$definitions[$name]);
|
||||
return isset(static::$definitions[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,10 +86,10 @@ abstract class Definition {
|
|||
protected static function load() {
|
||||
$json = JSON::decode(file_get_contents(VZ_DIR . static::FILE));
|
||||
|
||||
self::$definitions = array();
|
||||
static::$definitions = array();
|
||||
|
||||
foreach ($json as $property) {
|
||||
self::$definitions[$property->name] = new static($property);
|
||||
static::$definitions[$property->name] = new static($property);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue