4 * This file is part of Psy Shell.
6 * (c) 2012-2017 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Psy\Command\ListCommand;
14 use Symfony\Component\Console\Input\InputInterface;
17 * Global Variable Enumerator class.
19 class GlobalVariableEnumerator extends Enumerator
24 protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null)
26 // only list globals when no Reflector is present.
27 if ($reflector !== null || $target !== null) {
31 // only list globals if we are specifically asked
32 if (!$input->getOption('globals')) {
36 $globals = $this->prepareGlobals($this->getGlobals());
38 if (empty($globals)) {
43 'Global Variables' => $globals,
48 * Get defined global variables.
52 protected function getGlobals()
56 $names = array_keys($GLOBALS);
60 foreach ($names as $name) {
61 $ret[$name] = $GLOBALS[$name];
68 * Prepare formatted global variable array.
70 * @param array $globals
74 protected function prepareGlobals($globals)
76 // My kingdom for a generator.
79 foreach ($globals as $name => $value) {
80 if ($this->showItem($name)) {
84 'style' => self::IS_GLOBAL,
85 'value' => $this->presentRef($value),