|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: caoyangmin |
|
5
|
|
|
* Date: 2018/6/14 |
|
6
|
|
|
* Time: 下午2:10 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace PhpBoot\Console; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use DI\FactoryInterface; |
|
13
|
|
|
|
|
14
|
|
|
class ConsoleContainer |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
private $className; |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $moduleName; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
private $description; |
|
28
|
|
|
/** |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
private $summary; |
|
32
|
|
|
/** |
|
33
|
|
|
* @var Command[] |
|
34
|
|
|
*/ |
|
35
|
|
|
private $commands = []; |
|
36
|
|
|
/** |
|
37
|
|
|
* @var object |
|
38
|
|
|
*/ |
|
39
|
|
|
private $instance; |
|
40
|
|
|
/** |
|
41
|
|
|
* @var FactoryInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
private $factory; |
|
44
|
|
|
|
|
45
|
1 |
|
public function __construct(FactoryInterface $factory, $className) |
|
46
|
|
|
{ |
|
47
|
1 |
|
$this->factory = $factory; |
|
48
|
1 |
|
$this->className = $className; |
|
49
|
1 |
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
public function getClassName() |
|
52
|
|
|
{ |
|
53
|
1 |
|
return $this->className; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return Command[] |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function getCommands() |
|
60
|
|
|
{ |
|
61
|
1 |
|
return $this->commands; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
1 |
|
public function getCommand($target) |
|
65
|
|
|
{ |
|
66
|
1 |
|
return isset($this->commands[$target])?$this->commands[$target]:null; |
|
67
|
|
|
} |
|
68
|
|
|
/** |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getDescription() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->description; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
1 |
|
public function getSummary() |
|
80
|
|
|
{ |
|
81
|
1 |
|
return $this->summary; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
1 |
|
public function setDescription($description) |
|
85
|
|
|
{ |
|
86
|
1 |
|
$this->description = $description; |
|
87
|
1 |
|
} |
|
88
|
|
|
|
|
89
|
1 |
|
public function setSummary($summary) |
|
90
|
|
|
{ |
|
91
|
1 |
|
$this->summary = $summary; |
|
92
|
1 |
|
} |
|
93
|
|
|
|
|
94
|
1 |
|
public function setModuleName($name) |
|
95
|
|
|
{ |
|
96
|
1 |
|
$this->moduleName = $name; |
|
97
|
1 |
|
} |
|
98
|
|
|
|
|
99
|
1 |
|
public function addCommand($target, Command $command) |
|
100
|
|
|
{ |
|
101
|
1 |
|
$this->commands[$target] = $command; |
|
102
|
1 |
|
} |
|
103
|
1 |
|
public function postCreate() |
|
104
|
|
|
{ |
|
105
|
1 |
|
foreach ($this->commands as $command){ |
|
106
|
1 |
|
$command->postCreate($this); |
|
107
|
1 |
|
} |
|
108
|
1 |
|
} |
|
109
|
1 |
|
public function getModuleName() |
|
110
|
|
|
{ |
|
111
|
1 |
|
return $this->moduleName; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @return mixed|object |
|
116
|
|
|
* @throws \DI\DependencyException |
|
117
|
|
|
* @throws \DI\NotFoundException |
|
118
|
|
|
*/ |
|
119
|
1 |
|
public function getInstance() |
|
120
|
|
|
{ |
|
121
|
1 |
|
if(!$this->instance ){ |
|
122
|
1 |
|
$this->instance = $this->factory->make($this->getClassName()); |
|
123
|
1 |
|
} |
|
124
|
1 |
|
return $this->instance; |
|
125
|
|
|
} |
|
126
|
|
|
} |