Completed
Push — master ( 2361e9...c31a8f )
by Dmitrij
11s
created

ProcessLayoutFile::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace HotRodCli\Processors;
4
5
use HotRodCli\AppContainer;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Console\Input\ArrayInput;
9
use Symfony\Component\Console\Application;
10
11
class ProcessLayoutFile
12
{
13
    protected $appContainer;
14
15
    public function __construct(AppContainer $appContainer)
16
    {
17
        $this->appContainer = $appContainer;
18
    }
19
20
    public function __invoke(InputInterface $input, OutputInterface $output)
21
    {
22
        if (!$input->getOption('no-layout')) {
23
            $app = $this->appContainer;
24
25
            /** @var Application $application */
26
            $application = $app->resolve(Application::class);
27
            $command = $application->find('create:layout');
28
29
            $inputs = $this->constructInputs($input);
30
31
            if ($input->getOption('admin')) {
32
                $inputs['--admin'] = true;
33
            }
34
35
            $greetInput = new ArrayInput($inputs);
36
            $command->run($greetInput, $output);
37
        }
38
    }
39
40
    protected function constructInputs(InputInterface $input)
41
    {
42
        $namespace = explode('_', $input->getArgument('namespace'));
43
        $controller = explode('/', $input->getArgument('route'));
44
45
        return [
46
            'namespace' => $input->getArgument('namespace'),
47
            'layout-name' => strtolower($controller[0]) . '_' . strtolower($controller[1]) . '_' . strtolower($controller[2]),
48
            'layout-file-name' => strtolower($controller[0]) . '_' . strtolower($controller[1]) . '_' . strtolower($controller[2]),
49
            'block-class' => $namespace[0] . '\\' . $namespace[1] . '\\Block\\' . ucwords($controller[1]),
50
            'template' => $controller[2]
51
        ];
52
    }
53
}
54