forked from modstart/ModStartBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClosureCommand.php
More file actions
50 lines (33 loc) · 1.12 KB
/
Copy pathClosureCommand.php
File metadata and controls
50 lines (33 loc) · 1.12 KB
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 Module\Vendor\Shell;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ClosureCommand extends Command
{
protected $callback;
public function __construct($signature, \Closure $callback)
{
$this->callback = $callback;
$this->signature = $signature;
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$inputs = array_merge($input->getArguments(), $input->getOptions());
$parameters = [];
foreach ((new \ReflectionFunction($this->callback))->getParameters() as $parameter) {
if (isset($inputs[$parameter->name])) {
$parameters[$parameter->name] = $inputs[$parameter->name];
}
}
return $this->laravel->call(
$this->callback->bindTo($this, $this), $parameters
);
}
public function describe($description)
{
$this->setDescription($description);
return $this;
}
}