comparison vendor/psy/psysh/src/functions.php @ 16:c2387f117808

Routine composer update
author Chris Cannam
date Tue, 10 Jul 2018 15:07:59 +0100
parents 5fb285c0d0e3
children 129ea1e6d783
comparison
equal deleted inserted replaced
15:e200cb7efeb3 16:c2387f117808
26 * 26 *
27 * @return string 27 * @return string
28 */ 28 */
29 function sh() 29 function sh()
30 { 30 {
31 return 'extract(\Psy\debug(get_defined_vars(), isset($this) ? $this : null));'; 31 return 'extract(\Psy\debug(get_defined_vars(), isset($this) ? $this : @get_called_class()));';
32 } 32 }
33 } 33 }
34 34
35 if (!function_exists('Psy\debug')) { 35 if (!function_exists('Psy\debug')) {
36 /** 36 /**
48 * foreach ($items as $item) { 48 * foreach ($items as $item) {
49 * extract(\Psy\debug(get_defined_vars())); 49 * extract(\Psy\debug(get_defined_vars()));
50 * var_dump($item); // will be whatever you set $item to in Psy Shell 50 * var_dump($item); // will be whatever you set $item to in Psy Shell
51 * } 51 * }
52 * 52 *
53 * Optionally, supply an object as the `$boundObject` parameter. This 53 * Optionally, supply an object as the `$bindTo` parameter. This determines
54 * determines the value `$this` will have in the shell, and sets up class 54 * the value `$this` will have in the shell, and sets up class scope so that
55 * scope so that private and protected members are accessible: 55 * private and protected members are accessible:
56 * 56 *
57 * class Foo { 57 * class Foo {
58 * function bar() { 58 * function bar() {
59 * \Psy\debug(get_defined_vars(), $this); 59 * \Psy\debug(get_defined_vars(), $this);
60 * } 60 * }
61 * } 61 * }
62 * 62 *
63 * @param array $vars Scope variables from the calling context (default: array()) 63 * For the static equivalent, pass a class name as the `$bindTo` parameter.
64 * @param object $boundObject Bound object ($this) value for the shell 64 * This makes `self` work in the shell, and sets up static scope so that
65 * private and protected static members are accessible:
66 *
67 * class Foo {
68 * static function bar() {
69 * \Psy\debug(get_defined_vars(), get_called_class());
70 * }
71 * }
72 *
73 * @param array $vars Scope variables from the calling context (default: array())
74 * @param object|string $bindTo Bound object ($this) or class (self) value for the shell
65 * 75 *
66 * @return array Scope variables from the debugger session 76 * @return array Scope variables from the debugger session
67 */ 77 */
68 function debug(array $vars = [], $boundObject = null) 78 function debug(array $vars = [], $bindTo = null)
69 { 79 {
70 echo PHP_EOL; 80 echo PHP_EOL;
71 81
72 $sh = new Shell(); 82 $sh = new Shell();
73 $sh->setScopeVariables($vars); 83 $sh->setScopeVariables($vars);
77 // @todo come up with a better way of doing this which doesn't involve injecting input :-P 87 // @todo come up with a better way of doing this which doesn't involve injecting input :-P
78 if ($sh->has('whereami')) { 88 if ($sh->has('whereami')) {
79 $sh->addInput('whereami -n2', true); 89 $sh->addInput('whereami -n2', true);
80 } 90 }
81 91
82 if ($boundObject !== null) { 92 if (is_string($bindTo)) {
83 $sh->setBoundObject($boundObject); 93 $sh->setBoundClass($bindTo);
94 } elseif ($bindTo !== null) {
95 $sh->setBoundObject($bindTo);
84 } 96 }
85 97
86 $sh->run(); 98 $sh->run();
87 99
88 return $sh->getScopeVariables(false); 100 return $sh->getScopeVariables(false);