Skip to content

Commit

Permalink
#4 Adding krumo::queue()
Browse files Browse the repository at this point in the history
  • Loading branch information
kktsvetkov committed Aug 3, 2020
1 parent bcdcaa0 commit 2ca53ac
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,27 @@ be called using static calls to the Krumo class. Here are several more examples:
```
... and so on, etc.


Please note that the first time you call `Krumo` the dump it produces also
prints the CSS and the JS code used to expand/collapse the dump nodes.

### krumo::fetch()

If you want to get the output returned instead of printed, you can use
the `krumo::fetch()` method for that:
```php
$a = krumo::fetch($app, $env);
```
Please note that the first time you call `Krumo` the dump it produces also
prints the CSS and the JS code used to expand/collapse the dump nodes.

### krumo::queue()

It's been a valid complain that sometimes Krumo output is called in the middle
of some opened HTML tag, and that breaks the output of both that tag and Krumo
itself. You can use `krumo::queue()` instead of `krumo::dump()` to solve that
problem, since `krumo::queue()` will print its output at the end of the script:
```php
krumo::queue($request);
```

## Skins

Expand Down
45 changes: 30 additions & 15 deletions class.krumo.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
class krumo
{
const version = '0.4.3';
const version = '0.4.4';

/**
* Prints a debug backtrace
Expand Down Expand Up @@ -522,10 +522,10 @@ static function dump($data)
//
if (func_num_args() > 1)
{
$_ = func_get_args();
foreach($_ as $d)
$args = func_get_args();
foreach($args as $arg)
{
self::dump($d);
self::dump( $arg );
}

return true;
Expand All @@ -537,8 +537,8 @@ static function dump($data)

// find caller
//
$_ = debug_backtrace(1); // "1" is DEBUG_BACKTRACE_IGNORE_ARGS
while($d = array_pop($_))
$trace = debug_backtrace(1); // "1" is DEBUG_BACKTRACE_IGNORE_ARGS
while($d = array_pop($trace))
{
if (0 === strcasecmp($d['function'], 'krumo'))
{
Expand Down Expand Up @@ -643,8 +643,8 @@ static function dump($data)
}

/**
* Return the dump information about a variable
* @param mixed $data,...
* Return the dump information about variable\variables
* @param mixed $data,... pass as many arguments as you want
* @return string
*/
static function fetch($data)
Expand All @@ -658,13 +658,29 @@ static function fetch($data)

ob_start();
call_user_func_array(
array(__CLASS__, 'dump'),
array(get_called_class(), 'dump'),
func_get_args()
);

return ob_get_clean();
}

/**
* Prints the dump information about variable\variables at end of a script
* @param mixed $data,... pass as many arguments as you want
* @return string
*/
static function queue($data)
{
$output = call_user_func_array(
array(get_called_class(), 'fetch'),
func_get_args()
);

register_shutdown_function('printf', '%s', $output);
return $output;
}

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

/**
Expand Down Expand Up @@ -945,7 +961,7 @@ private static function _marker()
*/
private static function &_hive(&$bee)
{
static $_ = array();
static $_bee_hive = array();

// new bee ?
//
Expand All @@ -964,12 +980,12 @@ private static function &_hive(&$bee)
: $bee[$_recursion_marker]++
);

$_[0][] =& $bee; // KT: stupid PHP4 static reference hack
$_bee_hive[0][] =& $bee; // KT: stupid static reference hack
}

// return all bees
//
return $_[0];
return $_bee_hive[0];
}

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Expand All @@ -987,14 +1003,13 @@ private static function _vars(&$data)
// prevent endless recursion loops
//
$_recursion_marker = self::_marker();
$_r = ($_is_object)
$has_recursion = ($_is_object)
? !empty($data->$_recursion_marker)
: !empty($data[$_recursion_marker]) ;
$_r = (integer) $_r;

// recursion detected
//
if ($_r > 0)
if ($has_recursion)
{
return self::_recursion();
}
Expand Down

0 comments on commit 2ca53ac

Please sign in to comment.