-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathChainedCommand.php
50 lines (45 loc) · 1.21 KB
/
ChainedCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace CLIFramework;
use CLIFramework\Command;
/**
* A ChainedCommand contains multiple commands together,
*
* Subcommands of a chained command use the same options,
* same logger, same application and are executed by sequence.
*/
class ChainedCommand extends Command
{
/**
* @var array Command class names
*/
public $commands = array();
public function options($opts)
{
$cmds = $this->getChainedCommands();
foreach ($cmds as $cmd) {
$cmd->options($opts);
}
}
public function getChainedCommands()
{
$cmds = array();
foreach ($this->commands as $command) {
$cmd = new $command($this->application);
$cmd->logger = $this->logger;
$cmd->parent = $this;
$cmds[] = $cmd;
}
return $cmds;
}
public function execute()
{
$this->logger->info('Executing chained commands: ' . join(',', $this->commands));
$args = func_get_args();
$cmds = $this->getChainedCommands();
foreach ($cmds as $cmd) {
$cmd->options = $this->options;
$cmd->executeWrapper($args);
}
$this->logger->info('Done');
}
}