91ba985d918d1d1428da031cebb92c3a4702ea87
[yaffs-website] / vendor / psy / psysh / src / Psy / Command / ListCommand / InterfaceEnumerator.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2017 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     }
28
29     /**
30      * {@inheritdoc}
31      */
32     protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null)
33     {
34         // only list interfaces when no Reflector is present.
35         //
36         // @todo make a NamespaceReflector and pass that in for commands like:
37         //
38         //     ls --interfaces Foo
39         //
40         // ... for listing interfaces in the Foo namespace
41
42         if ($reflector !== null || $target !== null) {
43             return;
44         }
45
46         // only list interfaces if we are specifically asked
47         if (!$input->getOption('interfaces')) {
48             return;
49         }
50
51         $interfaces = $this->prepareInterfaces(get_declared_interfaces());
52
53         if (empty($interfaces)) {
54             return;
55         }
56
57         return array(
58             'Interfaces' => $interfaces,
59         );
60     }
61
62     /**
63      * Prepare formatted interface array.
64      *
65      * @param array $interfaces
66      *
67      * @return array
68      */
69     protected function prepareInterfaces(array $interfaces)
70     {
71         natcasesort($interfaces);
72
73         // My kingdom for a generator.
74         $ret = array();
75
76         foreach ($interfaces as $name) {
77             if ($this->showItem($name)) {
78                 $ret[$name] = array(
79                     'name'  => $name,
80                     'style' => self::IS_CLASS,
81                     'value' => $this->presentSignature($name),
82                 );
83             }
84         }
85
86         return $ret;
87     }
88 }