1
|
|
|
<?php namespace Comodojo\Foundation\Console; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Foundation\Base\Configuration; |
4
|
|
|
use \Comodojo\Foundation\Base\ConfigurationTrait; |
5
|
|
|
use \Symfony\Component\Console\Application; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @package Comodojo Foundation |
9
|
|
|
* @author Marco Giovinazzi <[email protected]> |
10
|
|
|
* @license MIT |
11
|
|
|
* |
12
|
|
|
* LICENSE: |
13
|
|
|
* |
14
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
17
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
19
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
20
|
|
|
* THE SOFTWARE. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
class Processor { |
24
|
|
|
|
25
|
|
|
use ConfigurationTrait; |
26
|
|
|
|
27
|
|
|
protected $application; |
28
|
|
|
|
29
|
|
|
// $commands should be an array of classes |
30
|
|
|
|
31
|
|
|
public function __construct( |
32
|
|
|
Configuration $configuration, |
33
|
|
|
array $commands, |
34
|
|
|
$name = null, |
35
|
|
|
$version = null |
36
|
|
|
) { |
37
|
|
|
|
38
|
|
|
$this->setApplication(new Application()); |
39
|
|
|
$this->setConfiguration($configuration); |
40
|
|
|
|
41
|
|
|
if ( !empty($name) ) $this->application->setName($name); |
42
|
|
|
if ( !empty($version) ) $this->application->setVersion($version); |
43
|
|
|
|
44
|
|
|
foreach ($commands as $command) { |
45
|
|
|
|
46
|
|
|
$this->application->add( |
47
|
|
|
$command::init($configuration) |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function run() { |
55
|
|
|
|
56
|
|
|
$this->application->run(); |
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function setApplication(Application $application) { |
61
|
|
|
|
62
|
|
|
$this->application = $application; |
63
|
|
|
return $this; |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getApplication() { |
68
|
|
|
|
69
|
|
|
return $this->application; |
70
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public static function init( |
74
|
|
|
Configuration $configuration, |
75
|
|
|
array $commands, |
76
|
|
|
$name = null, |
77
|
|
|
$version = null |
78
|
|
|
) { |
79
|
|
|
|
80
|
|
|
return new Processor($configuration, $commands, $name, $version); |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|