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 * Function Enumerator class.
19 class FunctionEnumerator extends Enumerator
24 protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null)
26 // only list functions when no Reflector is present.
28 // @todo make a NamespaceReflector and pass that in for commands like:
32 // ... for listing functions in the Foo namespace
34 if ($reflector !== null || $target !== null) {
38 // only list functions if we are specifically asked
39 if (!$input->getOption('functions')) {
43 if ($input->getOption('user')) {
44 $label = 'User Functions';
45 $functions = $this->getFunctions('user');
46 } elseif ($input->getOption('internal')) {
47 $label = 'Internal Functions';
48 $functions = $this->getFunctions('internal');
51 $functions = $this->getFunctions();
54 $functions = $this->prepareFunctions($functions);
56 if (empty($functions)) {
61 $ret[$label] = $functions;
67 * Get defined functions.
69 * Optionally limit functions to "user" or "internal" functions.
71 * @param null|string $type "user" or "internal" (default: both)
75 protected function getFunctions($type = null)
77 $funcs = get_defined_functions();
82 return array_merge($funcs['internal'], $funcs['user']);
87 * Prepare formatted function array.
89 * @param array $functions
93 protected function prepareFunctions(array $functions)
95 natcasesort($functions);
97 // My kingdom for a generator.
100 foreach ($functions as $name) {
101 if ($this->showItem($name)) {
104 'style' => self::IS_FUNCTION,
105 'value' => $this->presentSignature($name),