Completed
Push — feature/php-7.1-partial ( 412847 )
by Tom
03:40
created

AbstractConsoleCommand::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace N98\Magento\Command\Developer\Console;
4
5
use Magento\Framework\App\ObjectManager;
6
use Psy\Command\ReflectingCommand;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
abstract class AbstractConsoleCommand extends ReflectingCommand
11
{
12
    /**
13
     * @param string $variable
14
     * @param mixed $value
15
     *
16
     * @return void
17
     */
18
    public function setScopeVariable($variable, $value)
19
    {
20
        $variables = $this->context->getAll();
21
        $variables[$variable] = $value;
22
23
        $this->context->setAll($variables);
24
    }
25
26
    /**
27
     * @param string $type
28
     * @return mixed
29
     */
30
    public function get($type)
31
    {
32
        $di = $this->getScopeVariable('di');
33
34
        /** @var $di ObjectManager */
35
        return $di->get($type);
36
    }
37
38
    /**
39
     * @param string $type
40
     * @param array $arguments
41
     * @return mixed
42
     */
43
    public function create($type, $arguments = [])
44
    {
45
        $di = $this->getScopeVariable('di');
46
47
        /** @var $di ObjectManager */
48
        return $di->create($type, $arguments);
49
    }
50
51
    /**
52
     * Call n98-magerun command
53
     *
54
     * @param string $commandName
55
     * @param InputInterface $input
56
     * @param OutputInterface $output
57
     * @return int
58
     */
59
    public function callMagerunCommand($commandName, InputInterface $input, OutputInterface $output)
60
    {
61
        $commandName = rtrim($commandName, ';');
62
        /** @var \N98\Magento\Command\AbstractMagentoCommand $command */
63
        $command = $this->getScopeVariable('magerun')->find($commandName);
64
65
        return $command->run($input, $output);
66
    }
67
68
    /**
69
     * Call psy console command
70
     *
71
     * @param InputInterface $input
72
     * @param OutputInterface $output
73
     * @return int
74
     */
75
    public function callCommand(InputInterface $input, OutputInterface $output)
76
    {
77
        if ($input->hasArgument('command')) {
78
            $commandName = $input->getArgument('command');
79
        } else {
80
            $commandName = $input->getFirstArgument();
81
        }
82
83
        $command = $this->getApplication()->find($commandName);
84
85
        return $command->run($input, $output);
86
    }
87
}
88