Completed
Push — master ( e57357...0c5664 )
by Alexander
9s
created

BaseAspectCommand::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
ccs 0
cts 14
cp 0
rs 9.4285
cc 3
eloc 10
nc 3
nop 2
crap 12
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2013, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Go\Console\Command;
12
13
use Go\Core\AspectKernel;
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * Base command for all aspect commands
21
 */
22
class BaseAspectCommand extends Command
23
{
24
    /**
25
     * Stores an instance of aspect kernel
26
     *
27
     * @var null|AspectKernel
28
     */
29
    protected $aspectKernel = null;
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    protected function configure()
35
    {
36
        $this->addArgument('loader', InputArgument::REQUIRED, "Path to the aspect loader file");
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    protected function execute(InputInterface $input, OutputInterface $output)
43
    {
44
        $loader = $input->getArgument('loader');
45
        $path   = stream_resolve_include_path($loader);
46
        if (!is_readable($path)) {
47
            throw new \InvalidArgumentException("Invalid loader path: {$loader}");
48
        }
49
        include_once $path;
50
51
        if (!class_exists(AspectKernel::class, false)) {
52
            $message = "Kernel was not initialized yet, please configure it in the {$path}";
53
            throw new \InvalidArgumentException($message);
54
        }
55
56
        $this->aspectKernel = AspectKernel::getInstance();
57
    }
58
}
59