mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Added $argCharLimit to SS_Backtrace::full_func_name(), to avoid printing really long strings its set to 10,000 by default
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@114137 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
7be01d3d10
commit
07c821c4a7
@ -75,8 +75,13 @@ class SS_Backtrace {
|
||||
|
||||
/**
|
||||
* Return the full function name. If showArgs is set to true, a string representation of the arguments will be shown
|
||||
*
|
||||
* @param Object $item
|
||||
* @param boolean $showArg
|
||||
* @param Int $argCharLimit
|
||||
* @return String
|
||||
*/
|
||||
static function full_func_name($item, $showArgs = false) {
|
||||
static function full_func_name($item, $showArgs = false, $argCharLimit = 10000) {
|
||||
$funcName = '';
|
||||
if(isset($item['class'])) $funcName .= $item['class'];
|
||||
if(isset($item['type'])) $funcName .= $item['type'];
|
||||
@ -86,7 +91,7 @@ class SS_Backtrace {
|
||||
$args = array();
|
||||
foreach($item['args'] as $arg) {
|
||||
if(!is_object($arg) || method_exists($arg, '__toString')) {
|
||||
$args[] = (string) $arg;
|
||||
$args[] = (strlen((string)$arg) > $argCharLimit) ? substr((string)$arg, 0, $argCharLimit) . '...' : (string)$arg;
|
||||
} else {
|
||||
$args[] = get_class($arg);
|
||||
}
|
||||
|
26
tests/dev/BacktraceTest.php
Normal file
26
tests/dev/BacktraceTest.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* @package sapphire
|
||||
* @subpackage tests
|
||||
*/
|
||||
class BacktraceTest extends SapphireTest {
|
||||
|
||||
function testFullFuncNameWithArgsAndCustomCharLimit() {
|
||||
$func = array(
|
||||
'class' => 'MyClass',
|
||||
'type' => '->',
|
||||
'file' => 'MyFile.php',
|
||||
'line' => 99,
|
||||
'function' => 'myFunction',
|
||||
'args' => array(
|
||||
'number' => 1,
|
||||
'mylongstring' => 'more than 20 characters 1234567890',
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'MyClass->myFunction(1,more than 20 charact...)',
|
||||
SS_Backtrace::full_func_name($func, true, 20)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user