Yaffs site version 1.1
[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 Symfony\Component\Console\Input\InputInterface;
15
16 /**
17  * Interface Enumerator class.
18  */
19 class InterfaceEnumerator extends Enumerator
20 {
21     /**
22      * {@inheritdoc}
23      */
24     protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null)
25     {
26         // only list interfaces when no Reflector is present.
27         //
28         // @todo make a NamespaceReflector and pass that in for commands like:
29         //
30         //     ls --interfaces Foo
31         //
32         // ... for listing interfaces in the Foo namespace
33
34         if ($reflector !== null || $target !== null) {
35             return;
36         }
37
38         // only list interfaces if we are specifically asked
39         if (!$input->getOption('interfaces')) {
40             return;
41         }
42
43         $interfaces = $this->prepareInterfaces(get_declared_interfaces());
44
45         if (empty($interfaces)) {
46             return;
47         }
48
49         return array(
50             'Interfaces' => $interfaces,
51         );
52     }
53
54     /**
55      * Prepare formatted interface array.
56      *
57      * @param array $interfaces
58      *
59      * @return array
60      */
61     protected function prepareInterfaces(array $interfaces)
62     {
63         natcasesort($interfaces);
64
65         // My kingdom for a generator.
66         $ret = array();
67
68         foreach ($interfaces as $name) {
69             if ($this->showItem($name)) {
70                 $ret[$name] = array(
71                     'name'  => $name,
72                     'style' => self::IS_CLASS,
73                     'value' => $this->presentSignature($name),
74                 );
75             }
76         }
77
78         return $ret;
79     }
80 }