Completed
Pull Request — master (#63)
by Robbie
07:48
created

LookupCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SilverLeague\Console\Command\Injector;
4
5
use SilverLeague\Console\Command\SilverStripeCommand;
6
use SilverLeague\Console\Framework\Utility\ObjectUtilities;
7
use SilverStripe\Core\Injector\Injector;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Shows which class is returned from the Injector
14
 *
15
 * @package silverstripe-console
16
 * @author  Robbie Averill <[email protected]>
17
 */
18
class LookupCommand extends SilverStripeCommand
19
{
20
    use ObjectUtilities;
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    protected function configure()
26
    {
27
        $this
28
            ->setName('injector:lookup')
29
            ->setAliases(['object:lookup'])
30
            ->setDescription('Shows which class is returned from an Injector reference')
31
            ->addArgument('className', InputArgument::REQUIRED, 'The class name to look up');
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    protected function execute(InputInterface $input, OutputInterface $output)
38
    {
39
        $className = $input->getArgument('className');
40
        $resolvedTo = get_class(Injector::inst()->get($className));
41
42
        $output->writeln('<comment>' . $className . '</comment> resolves to <info>' . $resolvedTo . '</info>');
43
        if ($module = $this->getModuleName($resolvedTo)) {
44
            $output->writeln('<info>Module:</info> <comment>' . $module . '</comment>');
45
        }
46
    }
47
}
48