Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of Psy Shell.
5
 *
200 lars 6
 * (c) 2012-2023 Justin Hileman
148 lars 7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Psy\Command\ListCommand;
13
 
14
use Psy\Formatter\SignatureFormatter;
15
use Psy\Input\FilterOptions;
16
use Psy\Util\Mirror;
17
use Psy\VarDumper\Presenter;
18
use Symfony\Component\Console\Input\InputInterface;
19
 
20
/**
21
 * Abstract Enumerator class.
22
 */
23
abstract class Enumerator
24
{
25
    // Output styles
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';
33
 
34
    private $filter;
35
    private $presenter;
36
 
37
    /**
38
     * Enumerator constructor.
39
     *
40
     * @param Presenter $presenter
41
     */
42
    public function __construct(Presenter $presenter)
43
    {
44
        $this->filter = new FilterOptions();
45
        $this->presenter = $presenter;
46
    }
47
 
48
    /**
49
     * Return a list of categorized things with the given input options and target.
50
     *
51
     * @param InputInterface  $input
52
     * @param \Reflector|null $reflector
53
     * @param mixed           $target
54
     *
55
     * @return array
56
     */
57
    public function enumerate(InputInterface $input, \Reflector $reflector = null, $target = null): array
58
    {
59
        $this->filter->bind($input);
60
 
61
        return $this->listItems($input, $reflector, $target);
62
    }
63
 
64
    /**
65
     * Enumerate specific items with the given input options and target.
66
     *
67
     * Implementing classes should return an array of arrays:
68
     *
69
     *     [
70
     *         'Constants' => [
71
     *             'FOO' => [
72
     *                 'name'  => 'FOO',
73
     *                 'style' => 'public',
74
     *                 'value' => '123',
75
     *             ],
76
     *         ],
77
     *     ]
78
     *
79
     * @param InputInterface  $input
80
     * @param \Reflector|null $reflector
81
     * @param mixed           $target
82
     *
83
     * @return array
84
     */
85
    abstract protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array;
86
 
87
    protected function showItem($name)
88
    {
89
        return $this->filter->match($name);
90
    }
91
 
92
    protected function presentRef($value)
93
    {
94
        return $this->presenter->presentRef($value);
95
    }
96
 
97
    protected function presentSignature($target)
98
    {
99
        // This might get weird if the signature is actually for a reflector. Hrm.
100
        if (!$target instanceof \Reflector) {
101
            $target = Mirror::get($target);
102
        }
103
 
104
        return SignatureFormatter::format($target);
105
    }
106
}