Skip to content

Commit

Permalink
Move Psy\Shell::debug() to Psy\debug()
Browse files Browse the repository at this point in the history
It fits better there, and we've already got a functions file, so we might as well use it :)
  • Loading branch information
bobthecow committed Jun 16, 2017
1 parent 8f14ff2 commit d7aaa3f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 45 deletions.
47 changes: 3 additions & 44 deletions src/Psy/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,8 @@ public static function isIncluded(array $trace)
/**
* Invoke a Psy Shell from the current context.
*
* For example:
*
* foreach ($items as $item) {
* \Psy\Shell::debug(get_defined_vars());
* }
*
* If you would like your shell interaction to affect the state of the
* current context, you can extract() the values returned from this call:
*
* foreach ($items as $item) {
* extract(\Psy\Shell::debug(get_defined_vars()));
* var_dump($item); // will be whatever you set $item to in Psy Shell
* }
*
* Optionally, supply an object as the `$boundObject` parameter. This
* determines the value `$this` will have in the shell, and sets up class
* scope so that private and protected members are accessible:
*
* class Foo {
* function bar() {
* \Psy\Shell::debug(get_defined_vars(), $this);
* }
* }
*
* This only really works in PHP 5.4+ and HHVM 3.5+, so upgrade already.
* @see Psy\debug
* @deprecated will be removed in 1.0. Use \Psy\debug instead
*
* @param array $vars Scope variables from the calling context (default: array())
* @param object $boundObject Bound object ($this) value for the shell
Expand All @@ -137,25 +114,7 @@ public static function isIncluded(array $trace)
*/
public static function debug(array $vars = array(), $boundObject = null)
{
echo PHP_EOL;

$sh = new \Psy\Shell();
$sh->setScopeVariables($vars);

// Show a couple of lines of call context for the debug session.
//
// @todo come up with a better way of doing this which doesn't involve injecting input :-P
if ($sh->has('whereami')) {
$sh->addInput('whereami -n2', true);
}

if ($boundObject !== null) {
$sh->setBoundObject($boundObject);
}

$sh->run();

return $sh->getScopeVariables(false);
return \Psy\debug($vars, $boundObject);
}

/**
Expand Down
61 changes: 60 additions & 1 deletion src/Psy/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,66 @@
*/
function sh()
{
return 'extract(\Psy\Shell::debug(get_defined_vars(), isset($this) ? $this : null));';
return 'extract(\Psy\debug(get_defined_vars(), isset($this) ? $this : null));';
}
}

if (!function_exists('Psy\debug')) {
/**
* Invoke a Psy Shell from the current context.
*
* For example:
*
* foreach ($items as $item) {
* \Psy\debug(get_defined_vars());
* }
*
* If you would like your shell interaction to affect the state of the
* current context, you can extract() the values returned from this call:
*
* foreach ($items as $item) {
* extract(\Psy\debug(get_defined_vars()));
* var_dump($item); // will be whatever you set $item to in Psy Shell
* }
*
* Optionally, supply an object as the `$boundObject` parameter. This
* determines the value `$this` will have in the shell, and sets up class
* scope so that private and protected members are accessible:
*
* class Foo {
* function bar() {
* \Psy\debug(get_defined_vars(), $this);
* }
* }
*
* This only really works in PHP 5.4+ and HHVM 3.5+, so upgrade already.
*
* @param array $vars Scope variables from the calling context (default: array())
* @param object $boundObject Bound object ($this) value for the shell
*
* @return array Scope variables from the debugger session
*/
function debug(array $vars = array(), $boundObject = null)
{
echo PHP_EOL;

$sh = new Shell();
$sh->setScopeVariables($vars);

// Show a couple of lines of call context for the debug session.
//
// @todo come up with a better way of doing this which doesn't involve injecting input :-P
if ($sh->has('whereami')) {
$sh->addInput('whereami -n2', true);
}

if ($boundObject !== null) {
$sh->setBoundObject($boundObject);
}

$sh->run();

return $sh->getScopeVariables(false);
}
}

Expand Down

0 comments on commit d7aaa3f

Please sign in to comment.