public static function dump() { $message = ''; foreach (func_get_args() as $v) { $message .= ($message ? "\n" : '') . wa_dump_helper($v); } throw new self($message, 500); }
/** * Smarty plugin to print all template vars similar to print_r in a <pre> block. * Uses webasyst library helpers. Does not work outside of WA framework without further adjustments. * * Type: function<br> * Name: wa_template_vars<br> * Purpose: Print all template vars similar to print_r in a <pre> block.<br> * @param array * @param Smarty * @return string */ function smarty_function_wa_tpl_vars($params, &$smarty) { $str = '<div style="overflow: auto; min-width: 500px; height: 400px;"><pre>' . "\n\n"; $v = $smarty->getTemplateVars(); $str .= wa_dump_helper($v); // $smarty->tpl_vars $str .= "\n\n</pre></div>"; return $str; }
protected function __construct(waSystemConfig $config) { $this->config = $config; try { $this->loadFactories(); } catch (Exception $e) { $app_name = method_exists($config, 'getApplication') ? $config->getApplication() : ''; waLog::log('Error initializing waSystem(' . $app_name . '): ' . $e->getMessage() . "\n" . wa_dump_helper($config)); echo $e; } }
public static function dump($var, $file = 'dump.log') { $result = ''; // Show where we've been called from if (function_exists('debug_backtrace')) { $result .= "dumped from "; foreach (debug_backtrace() as $row) { if (ifset($row['file']) == __FILE__ || empty($row['file']) && ifset($row['function']) == 'wa_dumpc') { continue; } $result .= ifset($row['file'], '???') . ' line #' . ifset($row['line'], '???') . ":\n"; break; } } $result .= wa_dump_helper($var) . "\n"; waLog::log($result, $file); }
/** * Helper function for wa_print_r() / wa_dump() */ function wa_dump_helper(&$value, &$level_arr = array(), $cli = null) { $level_arr || ($level_arr = array()); $cli === null && ($cli = php_sapi_name() == 'cli'); $level = count($level_arr); if ($level > 29) { // Being paranoid return '** Too big level of nesting **'; } // Simple types if (!is_array($value) && !is_object($value)) { $result = var_export($value, true); if (!$cli) { $result = htmlspecialchars($result); } return $result; } // So, we have a nested type like array or object. // Check for recursion, and build line break with tabs $br = "\n"; foreach ($level_arr as $k => &$v) { $br .= " "; // Check for references we've already seen. // This avoids infinite recursion. $same = false; if (is_array($v) && is_array($value)) { // Checking whether arrays are same is not that trivial. // === operator will try to compare them recursively and fail // when array contains a reference to itself. // So, we use a clever trick here. $key = uniqid('same?', true); $v[$key] = $key; $same = isset($value[$key]) && $value[$key] === $key; unset($v[$key]); } else { if ($v === $value) { $same = true; } } if ($same) { return (is_object($value) ? get_class($value) . ' object' : 'Array') . ' ** RECURSION (level ' . ($k - $level) . ') **'; } } unset($v); if (is_object($value)) { // Skip huge core objects in nested structures if ($level > 0) { $huge_classes = array_flip(array('waSystem', 'waModel', 'waSmarty3View', 'waViewHelper', 'waWorkflow', 'Smarty', 'Smarty_Internal_Template')); $class = get_class($value); do { if (isset($huge_classes[$class])) { return get_class($value) . " object { ** skipped" . (isset($huge_classes[get_class($value)]) ? '' : " as a descendant of {$class}") . ' ** }'; } } while ($class = get_parent_class($class)); } $str = get_class($value) . ' object'; // Cast to array to show protected and private members $value_to_iterate = (array) $value; if ($value_to_iterate) { $str .= $br . '{'; } else { return $str . ' {}'; } } else { $str = 'Array'; if ($value) { $str .= $br . '('; } else { return $str . '()'; } $value_to_iterate =& $value; } $level_arr[] =& $value; foreach ($value_to_iterate as $key => &$val) { if (!$cli) { $key = htmlspecialchars($key); } $str .= $br . " " . $key . ' => ' . wa_dump_helper($val, $level_arr, $cli); } array_pop($level_arr); $str .= is_array($value) ? $br . ')' : $br . '}'; return $str; }