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
|
|
|
* Loads aspect kernel. |
41
|
|
|
* |
42
|
|
|
* Aspect kernel is loaded by executing loader and fetching singleton instance. |
43
|
|
|
* If your application environment initializes aspect kernel differently, you may |
44
|
|
|
* modify this metod to get aspect kernel suitable to your needs. |
45
|
|
|
* |
46
|
|
|
* @param InputInterface $input |
47
|
|
|
* @param OutputInterface $output |
48
|
|
|
*/ |
49
|
|
|
protected function loadAspectKernel(InputInterface $input, OutputInterface $output) |
50
|
|
|
{ |
51
|
|
|
$loader = $input->getArgument('loader'); |
52
|
|
|
$path = stream_resolve_include_path($loader); |
53
|
|
|
if (!is_readable($path)) { |
54
|
|
|
throw new \InvalidArgumentException("Invalid loader path: {$loader}"); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
ob_start(); |
58
|
|
|
include_once $path; |
59
|
|
|
ob_clean(); |
60
|
|
|
|
61
|
|
|
if (!class_exists(AspectKernel::class, false)) { |
62
|
|
|
$message = "Kernel was not initialized yet, please configure it in the {$path}"; |
63
|
|
|
throw new \InvalidArgumentException($message); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$this->aspectKernel = AspectKernel::getInstance(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|