Changeset 6017


Ignore:
Timestamp:
02/05/12 19:56:14 (4 months ago)
Author:
vain
Message:
  • isolated getWhereDebugWasCalled()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/debug/debug.core.php

    r5832 r6017  
    130130        exit; 
    131131    } 
    132      
     132 
    133133    /** 
    134134     * Displays the content of a variable with var_dump. 
     
    146146 
    147147        /** 
    148          * if xdebug is on and overloaded the var_dump function,  
     148         * if xdebug is on and overloaded the var_dump function, 
    149149         * then the output is already properly escaped and prepared for direct output. 
    150150         * if xdebug is off, we need to apply escaping ourself. 
     
    159159        # output the content of the buffer 
    160160        echo $var_dump; 
    161          
     161 
    162162        if($stop === true) 
    163163        { 
     
    169169     * Debug logs the output of $var to the firebug console 
    170170     * 
    171      * @param mixed $var 
    172      * @param $firebugmethod log,info,warn, error 
    173      * @param $backtrace boolean Enables tracing of the origin of the debug call (adds a seconds fb msg). 
     171     * @param mixed $var The variable to debug. 
     172     * @param $firebugmethod The firebug method to call (log,info,warn, error). Defaults to "log". 
     173     * 
    174174     * @return Content of $var will be returned via Header and is displayed in the FireBugConsole. 
    175175     */ 
     
    184184        $firephp = FirePHP::getInstance(true); 
    185185 
    186         # get callstack and log the origin of the call to Clansuite_Debug::firebug() 
    187         $backtrace_array = array(); 
    188         $backtrace_array = debug_backtrace(); 
    189  
    190         # check if debug origin was inside class/method or function, adjust message 
    191         $classname = ''; 
    192         if(isset($backtrace_array[1]['class']) == false) 
    193         { 
    194             $classname = ''; 
    195         } 
    196         else 
    197         { 
    198             $classname = $backtrace_array[1]['class']; 
    199         } 
    200  
    201         $infomsg = sprintf('You are debugging like fire in %s->%s() on line "%s" in file "%s".', 
    202                 $classname, $backtrace_array[1]['function'], 
    203                 $backtrace_array[0]['line'], $backtrace_array[0]['file']); 
    204  
    205         $firephp->info($infomsg); 
    206  
    207         unset($infomsg, $backtrace_array); 
     186        /** 
     187         * Adds an info message about the position of the firebug call (origin). 
     188         * This is very helpful, if you spread Debug::firebug() calls all over your code. 
     189         */ 
     190        $firephp->info(self::getWhereDebugWasCalled()); 
    208191 
    209192        # debug the var 
    210193        $firephp->{$firebugmethod}($var); 
     194    } 
     195 
     196    /** 
     197     * Returns the position of a call. 
     198     * 
     199     * This is used in combination with Clansuite_Debug::firebug(), 
     200     * to determine the origin of the call. 
     201     * 
     202     * @param type $level default 1. 
     203     * @return string Message with origin of the debug call. 
     204     */ 
     205    public static function getWhereDebugWasCalled($level = 1) 
     206    { 
     207        $trace  = array(); 
     208        $file = $line = $function = $class = $object = ''; 
     209 
     210        $trace  = debug_backtrace(); 
     211        $file       = $trace[$level]['file']; 
     212        $line       = $trace[$level]['line']; 
     213        $function   = $trace[$level]['function']; 
     214        $class      = $trace[$level]['class']; 
     215 
     216        return sprintf('You are debugging like fire in %s->%s() on line "%s" in file "%s".', 
     217                $class, $function, $line, $file); 
    211218    } 
    212219 
     
    296303    { 
    297304        self::printR(parse_ini_file(get_cfg_var('cfg_file_path'), true)); 
    298     }     
     305    } 
    299306 
    300307    /** 
     
    307314        echo 'http wrapper: '. in_array('http', $w) ? 'yes':'no'. NL; 
    308315        echo 'https wrapper: '. in_array('https', $w) ? 'yes':'no'. NL; 
    309         echo 'wrappers: '. self::printR($w);         
     316        echo 'wrappers: '. self::printR($w); 
    310317    } 
    311318 
    312319    /** 
    313320     * Returns a list of all registered event listeners 
    314      * @return array  
     321     * @return array 
    315322     */ 
    316323    public static function getRegisteredEventListeners() 
Note: See TracChangeset for help on using the changeset viewer.