Quantcast
Channel: Seguridad Agile
Viewing all articles
Browse latest Browse all 264

Wrapper para php debug_backtrace()

$
0
0
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
y otras cosas que ahora no recuerdo, a medida que la vuelva a usar, la mejoraré
<?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
   * 
   */
  public static function vardumpLog($var) {
      $logger = sfContext::getInstance()->getLogger();
      $logger->info(
print_r($var,1));     
  }
}

Viewing all articles
Browse latest Browse all 264

Trending Articles


Girasoles para colorear


mayabang Quotes, Torpe Quotes, tanga Quotes


Tagalog Quotes About Crush – Tagalog Love Quotes


OFW quotes : Pinoy Tagalog Quotes


Long Distance Relationship Tagalog Love Quotes


Tagalog Quotes To Move on and More Love Love Love Quotes


5 Tagalog Relationship Rules


Best Crush Tagalog Quotes And Sayings 2017


Re:Mutton Pies (lleechef)


FORECLOSURE OF REAL ESTATE MORTGAGE


Sapos para colorear


tagalog love Quotes – Tiwala Quotes


Break up Quotes Tagalog Love Quote – Broken Hearted Quotes Tagalog


Patama Quotes : Tagalog Inspirational Quotes


Pamatay na Banat and Mga Patama Love Quotes


Tagalog Long Distance Relationship Love Quotes


BARKADA TAGALOG QUOTES


“BAHAY KUBO HUGOT”


Vimeo 10.7.0 by Vimeo.com, Inc.


Vimeo 10.7.1 by Vimeo.com, Inc.