X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FPsy%2Ffunctions.php;h=96e865fc36f345d9124a23e7d37cfc2dbb2cc123;hp=0576e04a3683aa22c3d39894ec63051b2fa8e7c5;hb=eba34333e3c89f208d2f72fa91351ad019a71583;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae diff --git a/vendor/psy/psysh/src/Psy/functions.php b/vendor/psy/psysh/src/Psy/functions.php index 0576e04a3..96e865fc3 100644 --- a/vendor/psy/psysh/src/Psy/functions.php +++ b/vendor/psy/psysh/src/Psy/functions.php @@ -28,7 +28,66 @@ if (!function_exists('Psy\sh')) { */ 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); } } @@ -253,7 +312,7 @@ EOL; } catch (Exception $e) { echo $e->getMessage() . PHP_EOL; - // TODO: this triggers the "exited unexpectedly" logic in the + // @todo this triggers the "exited unexpectedly" logic in the // ForkingLoop, so we can't exit(1) after starting the shell... // fix this :)