function safe_query($q = '', $debug = '', $unbuf = '') { global $DB, $txpcfg, $qcount, $qtime, $production_status; $method = !$unbuf ? 'mysql_query' : 'mysql_unbuffered_query'; if (!$q) { return false; } if ($debug or TXP_DEBUG === 1) { dmp($q); } $start = getmicrotime(); $result = $method($q, $DB->link); $time = sprintf('%02.6f', getmicrotime() - $start); @($qtime += $time); @$qcount++; if ($result === false and (txpinterface === 'admin' or @$production_status == 'debug' or @$production_status == 'testing')) { $caller = $production_status == 'debug' ? n . join("\n", get_caller()) : ''; trigger_error(mysql_error() . n . $q . $caller, E_USER_WARNING); } trace_add("[SQL ({$time}): {$q}]"); if (!$result) { return false; } return $result; }
function assert_int($myvar) { global $production_status; if (is_numeric($myvar) and $myvar == intval($myvar)) { return (int) $myvar; } if ($production_status == 'debug' || txpinterface == 'admin') { trigger_error("<pre>Error: '" . htmlspecialchars($myvar) . "' is not an integer</pre>" . n . '<pre style="padding-left: 2em;" class="backtrace"><code>' . htmlspecialchars(join(n, get_caller(5, 1))) . '</code></pre>', E_USER_ERROR); } else { trigger_error("'" . htmlspecialchars($myvar) . "' is not an integer.", E_USER_ERROR); } return false; }
function publicErrorHandler($errno, $errstr, $errfile, $errline) { global $production_status; $error = array(E_WARNING => "Warning", E_NOTICE => "Notice", E_USER_ERROR => "Textpattern Error", E_USER_WARNING => "Textpattern Warning", E_USER_NOTICE => "Textpattern Notice"); if (!($errno & error_reporting())) { return; } if ($production_status == 'live' || $production_status != 'debug' && $errno == E_USER_NOTICE) { return; } global $production_status; printf("<pre>" . gTxt('general_error') . ' <b>%s: %s on line %s</b></pre>', $error[$errno], $errstr, $errline); if ($production_status == 'debug') { print "\n<pre style=\"padding-left: 2em;\" class=\"backtrace\"><code>" . txpspecialchars(join("\n", get_caller(10))) . "</code></pre>"; } }
/** * * Muestra una query de manera friendly * @param unknown_type $query * @param unknown_type $results * @param unknown_type $params */ function show_query($query, $results = false, $params = false) { ?> <table cellpadding="5" style="border:3px solid #3E50B4;"> <tr style="background:#3E50B4;color:white;"> <th>Llamado desde</th> <th>Query</th> </tr> <tr> <td><?php echo get_caller(); ?> </td> <td><?php echo $query; ?> </td> </tr> <?php echo !$results && !$params ? "</table><hr>" : ""; ?> <?php }
/** * Error handler for public-side. * * @param int $errno * @param string $errstr * @param string $errfile * @param int $errline * @access private * @package Debug */ function publicErrorHandler($errno, $errstr, $errfile, $errline) { global $production_status; $error = array(); if ($production_status == 'testing') { $error = array(E_WARNING => 'Warning', E_USER_ERROR => 'Textpattern Error', E_USER_WARNING => 'Textpattern Warning'); } elseif ($production_status == 'debug') { $error = array(E_WARNING => 'Warning', E_NOTICE => 'Notice', E_USER_ERROR => 'Textpattern Error', E_USER_WARNING => 'Textpattern Warning', E_USER_NOTICE => 'Textpattern Notice'); if (!isset($error[$errno])) { $error[$errno] = $errno; } } if (!isset($error[$errno]) || !error_reporting()) { return; } printf("<pre dir=\"auto\">" . gTxt('general_error') . ' <b>%s: %s on line %s</b></pre>', $error[$errno], $errstr, $errline); if ($production_status == 'debug') { print "\n<pre class=\"backtrace\" dir=\"ltr\"><code>" . txpspecialchars(join("\n", get_caller(10))) . "</code></pre>"; } }
function query($q = '', $debug = '') { global $qcount, $qtime; if (!$q) { return false; } $start = getmicrotime(); $result = $this->DB->do_query($q, $this->DB->link); if ($debug or $this->_debug) { dmp($q, $result); } $time = sprintf('%02.6f', getmicrotime() - $start); @($qtime += $time); @$qcount++; if ($result === false and (txpinterface === 'admin' or !is_production_status('live'))) { $caller = is_production_status('debug') ? n . join("\n", get_caller()) : ''; trigger_error($this->DB->lasterror() . n . $q . $caller, E_USER_WARNING); } trace_add("[SQL ({$time}): {$q}]"); if (!$result) { return false; } return $result; }
/** * @covers \get_caller * @covers ::from */ public function testCanCallAsFunctionWithoutTrace() { // ---------------------------------------------------------------- // setup your test // ---------------------------------------------------------------- // perform the change $result = get_caller(); // ---------------------------------------------------------------- // test the results $this->assertInstanceOf(StackFrame::class, $result); $this->assertEquals('ReflectionMethod', $result->getClass()); $this->assertEquals('invokeArgs', $result->getMethod()); }