4531fce83ba06127582a4d0b2b300171adff5eed
[yaffs-website] / vendor / psy / psysh / src / Command / ListCommand / InterfaceEnumerator.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2018 Justin Hileman
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\VarDumper\Presenter;
15 use Symfony\Component\Console\Input\InputInterface;
16
17 /**
18  * Interface Enumerator class.
19  *
20  * @deprecated Nothing should use this anymore
21  */
22 class InterfaceEnumerator extends Enumerator
23 {
24     public function __construct(Presenter $presenter)
25     {
26         @\trigger_error('InterfaceEnumerator is no longer used', E_USER_DEPRECATED);
27         parent::__construct($presenter);
28     }
29
30     /**
31      * {@inheritdoc}
32      */
33     protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null)
34     {
35         // only list interfaces when no Reflector is present.
36         //
37         // @todo make a NamespaceReflector and pass that in for commands like:
38         //
39         //     ls --interfaces Foo
40         //
41         // ... for listing interfaces in the Foo namespace
42
43         if ($reflector !== null || $target !== null) {
44             return;
45         }
46
47         // only list interfaces if we are specifically asked
48         if (!$input->getOption('interfaces')) {
49             return;
50         }
51
52         $interfaces = $this->prepareInterfaces(\get_declared_interfaces());
53
54         if (empty($interfaces)) {
55             return;
56         }
57
58         return [
59             'Interfaces' => $interfaces,
60         ];
61     }
62
63     /**
64      * Prepare formatted interface array.
65      *
66      * @param array $interfaces
67      *
68      * @return array
69      */
70     protected function prepareInterfaces(array $interfaces)
71     {
72         \natcasesort($interfaces);
73
74         // My kingdom for a generator.
75         $ret = [];
76
77         foreach ($interfaces as $name) {
78             if ($this->showItem($name)) {
79                 $ret[$name] = [
80                     'name'  => $name,
81                     'style' => self::IS_CLASS,
82                     'value' => $this->presentSignature($name),
83                 ];
84             }
85         }
86
87         return $ret;
88     }
89 }