1 | <?php |
||
14 | class ClosureCommand extends Command |
||
15 | { |
||
16 | /** |
||
17 | * The command callback. |
||
18 | * |
||
19 | * @var \Closure |
||
20 | */ |
||
21 | protected $callback; |
||
22 | |||
23 | /** |
||
24 | * Create a new command instance. |
||
25 | * |
||
26 | * @param string $signature |
||
27 | * @param Closure $callback |
||
28 | * @return void |
||
|
|||
29 | */ |
||
30 | 1 | public function __construct($signature, Closure $callback) |
|
37 | |||
38 | /** |
||
39 | * Execute the console command. |
||
40 | * |
||
41 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
42 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
43 | * @return mixed |
||
44 | */ |
||
45 | protected function execute(InputInterface $input, OutputInterface $output) |
||
46 | { |
||
47 | $inputs = array_merge($input->getArguments(), $input->getOptions()); |
||
48 | |||
49 | $parameters = []; |
||
50 | |||
51 | foreach ((new ReflectionFunction($this->callback))->getParameters() as $parameter) { |
||
52 | if (isset($inputs[$parameter->name])) { |
||
53 | $parameters[$parameter->name] = $inputs[$parameter->name]; |
||
54 | } |
||
55 | } |
||
56 | |||
57 | return $this->laravel->call( |
||
58 | $this->callback->bindTo($this, $this), $parameters |
||
59 | ); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Set the description for the command. |
||
64 | * |
||
65 | * @param string $description |
||
66 | * @return $this |
||
67 | */ |
||
68 | 1 | public function describe($description) |
|
74 | } |
||
75 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.