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 Psy\Formatter\SignatureFormatter;
15 use Psy\Input\FilterOptions;
17 use Psy\VarDumper\Presenter;
18 use Symfony\Component\Console\Input\InputInterface;
21 * Abstract Enumerator class.
23 abstract class Enumerator
26 const IS_PUBLIC = 'public';
27 const IS_PROTECTED = 'protected';
28 const IS_PRIVATE = 'private';
29 const IS_GLOBAL = 'global';
30 const IS_CONSTANT = 'const';
31 const IS_CLASS = 'class';
32 const IS_FUNCTION = 'function';
38 * Enumerator constructor.
40 * @param Presenter $presenter
42 public function __construct(Presenter $presenter)
44 $this->filter = new FilterOptions();
45 $this->presenter = $presenter;
49 * Return a list of categorized things with the given input options and target.
51 * @param InputInterface $input
52 * @param Reflector $reflector
53 * @param mixed $target
57 public function enumerate(InputInterface $input, \Reflector $reflector = null, $target = null)
59 $this->filter->bind($input);
61 return $this->listItems($input, $reflector, $target);
65 * Enumerate specific items with the given input options and target.
67 * Implementing classes should return an array of arrays:
73 * 'style' => 'public',
79 * @param InputInterface $input
80 * @param Reflector $reflector
81 * @param mixed $target
85 abstract protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null);
87 protected function showItem($name)
89 return $this->filter->match($name);
92 protected function presentRef($value)
94 return $this->presenter->presentRef($value);
97 protected function presentSignature($target)
99 // This might get weird if the signature is actually for a reflector. Hrm.
100 if (!$target instanceof \Reflector) {
101 $target = Mirror::get($target);
104 return SignatureFormatter::format($target);