Ejemplo n.º 1
0
/**
 * Add a variable to the list of variables that will be shown in the debug window
 * @param mixed $var The variable you want to dump
 * @param mixed $name The name of the variable you want to dump
 */
function dump($var = null, $name = '(unknown name)', $type = null, $level = 0)
{
    global $mainframe;
    include_once JPATH_PLUGINS . DS . 'system' . DS . 'dump' . DS . 'node.php';
    $source = '';
    if (function_exists('debug_backtrace')) {
        $trace = debug_backtrace();
        $source = DumpHelper::getSourceFunction($trace);
        //$source .= '@';
        $source .= DumpHelper::getSourcePath($trace);
    }
    // create a new node array
    $node =& DumpNode::getNode($var, $name, $type, $level, $source);
    //get the current userstate
    $userstate = $mainframe->getUserState('dump.nodes');
    // append the node to the array
    $userstate[] = $node;
    // set the userstate to the new array
    $mainframe->setUserState('dump.nodes', $userstate);
}
Ejemplo n.º 2
0
/**
 * Add a variable to the list of variables that will be shown in the debug window
 * @param mixed $var The variable you want to dump
 * @param mixed $name The name of the variable you want to dump
 */
function dump($var = null, $name = '(unknown name)', $type = null, $level = 0)
{
    $mainframe = JFactory::getApplication();
    $option = JRequest::getCmd('option');
    require_once JPATH_ADMINISTRATOR . '/components/com_dump/node.php';
    $source = '';
    if (function_exists('debug_backtrace')) {
        $trace = debug_backtrace();
        $source = DumpHelper::getSourceFunction($trace);
        //$source .= '@';
        $source .= DumpHelper::getSourcePath($trace);
    }
    // create a new node array
    $node = DumpNode::getNode($var, $name, $type, $level, $source);
    //get the current userstate
    $userstate = $mainframe->getUserState('dump.nodes');
    // append the node to the array
    $userstate[] = $node;
    // set the userstate to the new array
    $mainframe->setUserState('dump.nodes', $userstate);
}
Ejemplo n.º 3
0
 function &getNode($var, $name, $type = null, $level = 0, $source = null)
 {
     $node['name'] = $name;
     $node['type'] = strtolower($type ? $type : gettype($var));
     $node['children'] = array();
     $node['level'] = $level;
     $node['source'] = $source;
     // expand the var according to type
     switch ($node['type']) {
         case 'backtrace':
             // Skip source when backtrace, and change to array
             $node['source'] = null;
             $node['type'] = 'array';
         case 'array':
             if ($level >= DumpHelper::getMaxDepth()) {
                 $node['children'][] =& DumpNode::getNode('Maximum depth reached', null, 'message');
             } else {
                 foreach ($var as $key => $value) {
                     $node['children'][] =& DumpNode::getNode($value, $key, null, $level + 1);
                 }
             }
             break;
         case 'object':
             if ($level >= DumpHelper::getMaxDepth()) {
                 $node['children'][] =& DumpNode::getNode('Maximum depth reached', null, 'message');
             } else {
                 $object_vars = get_object_vars($var);
                 $methods = get_class_methods($var);
                 if (count($object_vars)) {
                     $node['children'][] =& DumpNode::getNode($var, 'Properties', 'properties', $level);
                 }
                 if (count($methods)) {
                     $node['children'][] =& DumpNode::getNode($var, 'Methods', 'methods', $level);
                 }
             }
             $node['classname'] = get_class($var);
             break;
         case 'properties':
             $object_vars = get_object_vars($var);
             foreach ($object_vars as $key => $value) {
                 $node['children'][] =& DumpNode::getNode($value, $key, null, $level + 1);
             }
             break;
         case 'methods':
             $methods = get_class_methods($var);
             foreach ($methods as $value) {
                 $node['children'][] =& DumpNode::getNode(null, $value, 'method');
             }
             break;
         case 'string':
             jimport('joomla.application.component.helper');
             // settings from config.xml
             $dumpConfig =& JComponentHelper::getParams('com_dump');
             $trimstrings = $dumpConfig->get('trimstrings', 1);
             $maxstrlength = $dumpConfig->get('maxstrlength', 150);
             //original string length
             $length = JString::strlen($var);
             // trim string if needed
             if ($trimstrings and $length > $maxstrlength) {
                 $var = JString::substr($var, 0, $maxstrlength) . '...';
                 $node['length'] = $length;
             }
             $node['value'] = $var;
             break;
         default:
             $node['value'] =& $var;
             break;
     }
     return $node;
 }