1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Bldr.io |
5
|
|
|
* |
6
|
|
|
* (c) Aaron Scherer <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Bldr\Command; |
13
|
|
|
|
14
|
|
|
use Bldr\Application; |
15
|
|
|
use Bldr\Event\EventInterface; |
16
|
|
|
use Symfony\Component\Console\Command\Command; |
17
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
22
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Aaron Scherer <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
abstract class AbstractCommand extends Command implements ContainerAwareInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var ContainerInterface|ContainerBuilder $container |
31
|
|
|
*/ |
32
|
|
|
protected $container; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var InputInterface $input |
36
|
|
|
*/ |
37
|
|
|
protected $input; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var OutputInterface $output |
41
|
|
|
*/ |
42
|
|
|
protected $output; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @type HelperSet |
46
|
|
|
*/ |
47
|
|
|
protected $helperSet; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return int |
51
|
|
|
*/ |
52
|
|
|
abstract protected function doExecute(); |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
final protected function execute(InputInterface $input, OutputInterface $output) |
58
|
|
|
{ |
59
|
|
|
$this->setInput($input); |
60
|
|
|
$this->getApplication()->setBuildName(); |
61
|
|
|
$this->setOutput($output); |
62
|
|
|
$this->setHelperSet($this->getApplication()->getHelperSet()); |
63
|
|
|
|
64
|
|
|
$this->doExecute(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function setContainer(ContainerInterface $container = null) |
71
|
|
|
{ |
72
|
|
|
$this->container = $container; |
73
|
|
|
|
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string $name |
79
|
|
|
* @param EventInterface $event |
80
|
|
|
* |
81
|
|
|
* @return $this |
82
|
|
|
*/ |
83
|
|
|
public function addEvent($name, EventInterface $event) |
84
|
|
|
{ |
85
|
|
|
$this->container->get('bldr.dispatcher')->dispatch($name, $event); |
86
|
|
|
|
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return Application |
92
|
|
|
*/ |
93
|
|
|
public function getApplication() |
94
|
|
|
{ |
95
|
|
|
return parent::getApplication(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return InputInterface |
100
|
|
|
*/ |
101
|
|
|
public function getInput() |
102
|
|
|
{ |
103
|
|
|
return $this->input; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param InputInterface $input |
108
|
|
|
* |
109
|
|
|
* @return $this |
110
|
|
|
*/ |
111
|
|
|
protected function setInput(InputInterface $input) |
112
|
|
|
{ |
113
|
|
|
$this->input = $input; |
114
|
|
|
|
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return OutputInterface |
120
|
|
|
*/ |
121
|
|
|
public function getOutput() |
122
|
|
|
{ |
123
|
|
|
return $this->output; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param OutputInterface $output |
128
|
|
|
* |
129
|
|
|
* @return $this |
130
|
|
|
*/ |
131
|
|
|
protected function setOutput(OutputInterface $output) |
132
|
|
|
{ |
133
|
|
|
$this->output = $output; |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return HelperSet |
140
|
|
|
*/ |
141
|
|
|
public function getHelperSet() |
142
|
|
|
{ |
143
|
|
|
return $this->helperSet; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param HelperSet $helperSet |
148
|
|
|
* |
149
|
|
|
* @return AbstractCommand |
150
|
|
|
*/ |
151
|
|
|
public function setHelperSet(HelperSet $helperSet) |
152
|
|
|
{ |
153
|
|
|
$this->helperSet = $helperSet; |
154
|
|
|
|
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|