| 1: | <?php | 
| 2: | /* | 
| 3: | You may not change or alter any portion of this comment or credits | 
| 4: | of supporting developers from this source code or any supporting source code | 
| 5: | which is considered copyrighted (c) material of the original comment or credit authors. | 
| 6: | |
| 7: | This program is distributed in the hope that it will be useful, | 
| 8: | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 9: | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
| 10: | */ | 
| 11: | |
| 12: | namespace Xmf; | 
| 13: | |
| 14: | /** | 
| 15: | * Debugging tools for developers | 
| 16: | * | 
| 17: | * @category Xmf\Debug | 
| 18: | * @package Xmf | 
| 19: | * @author trabis <lusopoemas@gmail.com> | 
| 20: | * @author Richard Griffith <richard@geekwright.com> | 
| 21: | * @copyright 2011-2021 XOOPS Project (https://xoops.org) | 
| 22: | * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) | 
| 23: | * @link https://xoops.org | 
| 24: | */ | 
| 25: | class Debug extends \Kint | 
| 26: | { | 
| 27: | /** | 
| 28: | * doOnce - do some local housekeeping on first use. Any method needing this | 
| 29: | * assist just calls every time, the one time logic is all here. | 
| 30: | * | 
| 31: | * @return void | 
| 32: | */ | 
| 33: | private static function doOnce() | 
| 34: | { | 
| 35: | static $done; | 
| 36: | if (true !== $done) { | 
| 37: | $done = true; | 
| 38: | $class = get_called_class(); | 
| 39: | parent::$aliases[] = array($class, 'dump'); | 
| 40: | parent::$aliases[] = array($class, 'backtrace'); | 
| 41: | parent::$enabled_mode = true; | 
| 42: | parent::$mode_default = \Kint::MODE_RICH; | 
| 43: | // display output inline ::folder = false, true puts all output at bottom of window | 
| 44: | \Kint\Renderer\RichRenderer::$folder = false; | 
| 45: | // options: 'original' (default), 'solarized', 'solarized-dark' and 'aante-light' | 
| 46: | \Kint\Renderer\RichRenderer::$theme = 'aante-light.css'; | 
| 47: | } | 
| 48: | } | 
| 49: | |
| 50: | /** | 
| 51: | * Dump one or more variables | 
| 52: | * | 
| 53: | * @param mixed $data variable(s) to dump | 
| 54: | * | 
| 55: | * @return void | 
| 56: | */ | 
| 57: | public static function dump($data = null) | 
| 58: | { | 
| 59: | $args = func_get_args(); | 
| 60: | |
| 61: | static::doOnce(); | 
| 62: | forward_static_call_array(array('parent', 'dump'), $args); | 
| 63: | } | 
| 64: | |
| 65: | /** | 
| 66: | * Display debug backtrace | 
| 67: | * | 
| 68: | * @return void | 
| 69: | */ | 
| 70: | public static function backtrace() | 
| 71: | { | 
| 72: | static::doOnce(); | 
| 73: | static::trace(); | 
| 74: | } | 
| 75: | |
| 76: | /** | 
| 77: | * start_trace - turn on xdebug trace | 
| 78: | * | 
| 79: | * Requires xdebug extension | 
| 80: | * | 
| 81: | * @param string $tracefile file name for trace file | 
| 82: | * @param string $collect_params argument for ini_set('xdebug.collect_params',?) | 
| 83: | * Controls display of parameters in trace output | 
| 84: | * @param string $collect_return argument for ini_set('xdebug.collect_return',?) | 
| 85: | * Controls display of function return value in trace | 
| 86: | * | 
| 87: | * @return void | 
| 88: | */ | 
| 89: | public static function startTrace($tracefile = '', $collect_params = '3', $collect_return = 'On') | 
| 90: | { | 
| 91: | if (function_exists('xdebug_start_trace')) { | 
| 92: | ini_set('xdebug.collect_params', $collect_params); | 
| 93: | ini_set('xdebug.collect_return', $collect_return); | 
| 94: | if ($tracefile == '') { | 
| 95: | $tracefile = XOOPS_VAR_PATH . '/logs/php_trace'; | 
| 96: | } | 
| 97: | xdebug_start_trace($tracefile); | 
| 98: | } | 
| 99: | } | 
| 100: | |
| 101: | /** | 
| 102: | * stop_trace - turn off xdebug trace | 
| 103: | * | 
| 104: | * Requires xdebug extension | 
| 105: | * | 
| 106: | * @return void | 
| 107: | */ | 
| 108: | public static function stopTrace() | 
| 109: | { | 
| 110: | if (function_exists('xdebug_stop_trace')) { | 
| 111: | xdebug_stop_trace(); | 
| 112: | } | 
| 113: | } | 
| 114: | } | 
| 115: |