Esempio n. 1
0
 public static function trace(array $trace = NULL)
 {
     if ($trace === NULL) {
         $trace = debug_backtrace();
     }
     $statements = array('include', 'include_once', 'require', 'require_once');
     $output = array();
     foreach ($trace as $step) {
         if (!isset($step['function'])) {
             continue;
         }
         if (isset($step['file']) and isset($step['line'])) {
             $source = keke_debug::source($step['file'], $step['line']);
         }
         if (isset($step['file'])) {
             $file = $step['file'];
             if (isset($step['line'])) {
                 $line = $step['line'];
             }
         }
         $function = $step['function'];
         if (in_array($step['function'], $statements)) {
             if (empty($step['args'])) {
                 $args = array();
             } else {
                 $args = array($step['args'][0]);
             }
         } elseif (isset($step['args'])) {
             if (!function_exists($step['function']) or strpos($step['function'], '{closure}') !== FALSE) {
                 $params = NULL;
             } else {
                 if (isset($step['class'])) {
                     if (method_exists($step['class'], $step['function'])) {
                         $reflection = new ReflectionMethod($step['class'], $step['function']);
                     } else {
                         $reflection = new ReflectionMethod($step['class'], '__call');
                     }
                 } else {
                     $reflection = new ReflectionFunction($step['function']);
                 }
                 $params = $reflection->getParameters();
             }
             $args = array();
             foreach ($step['args'] as $i => $arg) {
                 if (isset($params[$i])) {
                     $args[$params[$i]->name] = $arg;
                 } else {
                     $args[$i] = $arg;
                 }
             }
         }
         if (isset($step['class'])) {
             $function = $step['class'] . $step['type'] . $step['function'];
         }
         $output[] = array('function' => $function, 'args' => isset($args) ? $args : NULL, 'file' => isset($file) ? $file : NULL, 'line' => isset($line) ? $line : NULL, 'source' => isset($source) ? $source : NULL);
         unset($function, $args, $file, $line, $source);
     }
     return $output;
 }