[+] Classes: add ObjectModel debug in overrides classes
This commit is contained in:
@@ -148,6 +148,15 @@ class FrontController extends FrontControllerCore
|
||||
return 'style="color:green"';
|
||||
}
|
||||
|
||||
private function getObjectModelColor($n)
|
||||
{
|
||||
if ($n > 50)
|
||||
return 'style="color:red"';
|
||||
if ($n > 10)
|
||||
return 'style="color:orange"';
|
||||
return 'style="color:green"';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
@@ -348,6 +357,7 @@ class FrontController extends FrontControllerCore
|
||||
<li><a href="#stopwatch">Go to Stopwatch</a></li>
|
||||
<li><a href="#doubles">Go to Doubles</a></li>
|
||||
<li><a href="#tables">Go to Tables</a></li>
|
||||
'.(isset(ObjectModel::$debug_list) ? '<li><a href="#objectModels">Go to ObjectModels</a></li>' : '').'
|
||||
</ul>
|
||||
</div>
|
||||
<div class="rte" style="text-align:left;padding:8px">
|
||||
@@ -370,5 +380,25 @@ class FrontController extends FrontControllerCore
|
||||
foreach ($tables as $table => $nb)
|
||||
echo $hr.'<b '.$this->getTableColor($nb).'>'.$nb.'</b> '.$table;
|
||||
echo '</div>';
|
||||
|
||||
if (isset(ObjectModel::$debug_list))
|
||||
{
|
||||
echo '<div class="rte" style="text-align:left;padding:8px">
|
||||
<h3><a name="objectModels">ObjectModel instances</a></h3>';
|
||||
$list = ObjectModel::$debug_list;
|
||||
uasort($list, create_function('$a,$b', 'return (count($a) < count($b)) ? 1 : -1;'));
|
||||
$i = 0;
|
||||
foreach ($list as $class => $info)
|
||||
{
|
||||
echo $hr.'<b '.$this->getObjectModelColor(count($info)).'>'.count($info).'</b> ';
|
||||
echo '<a href="#" onclick="$(\'#object_model_'.$i.'\').css(\'display\', $(\'#object_model_'.$i.'\').css(\'display\') == \'none\' ? \'block\' : \'none\'); return false">'.$class.'</a>';
|
||||
echo '<div id="object_model_'.$i.'" style="display: none">';
|
||||
foreach ($info as $trace)
|
||||
echo ltrim(str_replace(array(_PS_ROOT_DIR_, '\\'), array('', '/'), $trace['file']), '/').' ['.$trace['line'].']<br />';
|
||||
echo '</div>';
|
||||
$i++;
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
abstract class ObjectModel extends ObjectModelCore
|
||||
{
|
||||
public static $debug_list = array();
|
||||
|
||||
public function __construct($id = null, $id_lang = null, $id_shop = null)
|
||||
{
|
||||
parent::__construct($id, $id_lang, $id_shop);
|
||||
|
||||
$classname = get_class($this);
|
||||
if (!isset(self::$debug_list[$classname]))
|
||||
self::$debug_list[$classname] = array();
|
||||
|
||||
$class_list = array('ObjectModel', 'ObjectModelCore', $classname, $classname.'Core');
|
||||
$backtrace = debug_backtrace();
|
||||
foreach ($backtrace as $trace_id => $row)
|
||||
if (!isset($backtrace[$trace_id]['class']) || !in_array($backtrace[$trace_id]['class'], $class_list))
|
||||
break;
|
||||
$trace_id--;
|
||||
|
||||
self::$debug_list[$classname][] = array(
|
||||
'file' => @$backtrace[$trace_id]['file'],
|
||||
'line' => @$backtrace[$trace_id]['line'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user