Cada tanto me encuentro con la necesidad de debuggear symfony y con sus bellos e interminables objetos var_dump() no es opción, asi que cada tanto reinvento la rueda y confecciono algo como esta clase. Lo comparto con quien quiera y con mi mismo.
Lo que hace es al encontrar
- objetos poner la clase
- arrays poner la longitud
<?php
/**
* back_trace() prettifier
* @author Carlos Pantelides
* @license use and give credit where credit is due
* @date 2006-2012
* @todo add css
*/
class DebugUtil {
static public function backTrace($drop=0) {
$knownObjects = array();
$objectCount = 0;
$delim="\n";
$bt = debug_backtrace();
for ($i=0; $i<=$drop;$i++) {
unset($bt[$i]);
}
foreach ($bt as $key=>$level) {
if (isset($level['object'])) {
unset($bt[$key]['object']);
}
foreach($level['args'] as $subkey =>$arg) {
if (is_object($arg)) {
$objectId=spl_object_hash($arg);
if (! array_key_exists($objectId,$knownObjects)) {
$knownObjects[$objectId]=$objectCount;
$objectCount++;
}
$id = sprintf('%03d',$knownObjects[$objectId]);
@$bt[$key]['fixedArgs'].='OBJECT('.get_class($arg)."):$id, ";
} else if (is_array($arg)) {
@$bt[$key]['fixedArgs'].='ARRAY('. sizeof($arg).'), ';
} else if (is_resource($arg)) {
@$bt[$key]['fixedArgs'].='RESOURCE, ';
} else if (is_null($arg)) {
@$bt[$key]['fixedArgs'].='NULL, ';
} else if (is_string($arg)) {
@$bt[$key]['fixedArgs'].="'$arg', ";
} else {
$bt[$key]['fixedArgs'].="$arg, ";
}
}
@$bt[$key]['fixedArgs']=substr($bt[$key]['fixedArgs'],0,-2);
}
$result='';
foreach ($bt as $key=>$level) {
$result .= $level['class'] . '::' . $level['function'] .
'(' . $level['fixedArgs'] .') @' . $level['file'] . ':'.
$level['line'].$delim;
}
return $result;
}
/**
* Symfony 1.4
* @param mixed $var
*
class DebugUtil {
static public function backTrace($drop=0) {
$knownObjects = array();
$objectCount = 0;
$delim="\n";
$bt = debug_backtrace();
for ($i=0; $i<=$drop;$i++) {
unset($bt[$i]);
}
foreach ($bt as $key=>$level) {
if (isset($level['object'])) {
unset($bt[$key]['object']);
}
foreach($level['args'] as $subkey =>$arg) {
if (is_object($arg)) {
$objectId=spl_object_hash($arg);
if (! array_key_exists($objectId,$knownObjects)) {
$knownObjects[$objectId]=$objectCount;
$objectCount++;
}
$id = sprintf('%03d',$knownObjects[$objectId]);
@$bt[$key]['fixedArgs'].='OBJECT('.get_class($arg)."):$id, ";
} else if (is_array($arg)) {
@$bt[$key]['fixedArgs'].='ARRAY('. sizeof($arg).'), ';
} else if (is_resource($arg)) {
@$bt[$key]['fixedArgs'].='RESOURCE, ';
} else if (is_null($arg)) {
@$bt[$key]['fixedArgs'].='NULL, ';
} else if (is_string($arg)) {
@$bt[$key]['fixedArgs'].="'$arg', ";
} else {
$bt[$key]['fixedArgs'].="$arg, ";
}
}
@$bt[$key]['fixedArgs']=substr($bt[$key]['fixedArgs'],0,-2);
}
$result='';
foreach ($bt as $key=>$level) {
$result .= $level['class'] . '::' . $level['function'] .
'(' . $level['fixedArgs'] .') @' . $level['file'] . ':'.
$level['line'].$delim;
}
return $result;
}
/**
* Symfony 1.4
* @param mixed $var
*
*/
public static function vardumpLog($var) {
$logger = sfContext::getInstance()->getLogger();
$logger->info(print_r($var,1));
}
}
public static function vardumpLog($var) {
$logger = sfContext::getInstance()->getLogger();
$logger->info(print_r($var,1));
}
}
No hay comentarios:
Publicar un comentario