X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FPsy%2FCommand%2FListCommand%2FGlobalVariableEnumerator.php;fp=vendor%2Fpsy%2Fpsysh%2Fsrc%2FPsy%2FCommand%2FListCommand%2FGlobalVariableEnumerator.php;h=d957e9f52ed91a979bb6a50da66fe0d0f26bbf28;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/psy/psysh/src/Psy/Command/ListCommand/GlobalVariableEnumerator.php b/vendor/psy/psysh/src/Psy/Command/ListCommand/GlobalVariableEnumerator.php new file mode 100644 index 000000000..d957e9f52 --- /dev/null +++ b/vendor/psy/psysh/src/Psy/Command/ListCommand/GlobalVariableEnumerator.php @@ -0,0 +1,92 @@ +getOption('globals')) { + return; + } + + $globals = $this->prepareGlobals($this->getGlobals()); + + if (empty($globals)) { + return; + } + + return array( + 'Global Variables' => $globals, + ); + } + + /** + * Get defined global variables. + * + * @return array + */ + protected function getGlobals() + { + global $GLOBALS; + + $names = array_keys($GLOBALS); + natcasesort($names); + + $ret = array(); + foreach ($names as $name) { + $ret[$name] = $GLOBALS[$name]; + } + + return $ret; + } + + /** + * Prepare formatted global variable array. + * + * @param array $globals + * + * @return array + */ + protected function prepareGlobals($globals) + { + // My kingdom for a generator. + $ret = array(); + + foreach ($globals as $name => $value) { + if ($this->showItem($name)) { + $fname = '$' . $name; + $ret[$fname] = array( + 'name' => $fname, + 'style' => self::IS_GLOBAL, + 'value' => $this->presentRef($value), + ); + } + } + + return $ret; + } +}