Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Foundation\Console;
4
 
5
use Closure;
6
use Illuminate\Console\Command;
7
use ReflectionFunction;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
 
11
class ClosureCommand extends Command
12
{
13
    /**
14
     * The command callback.
15
     *
16
     * @var \Closure
17
     */
18
    protected $callback;
19
 
20
    /**
21
     * Create a new command instance.
22
     *
23
     * @param  string  $signature
24
     * @param  \Closure  $callback
25
     * @return void
26
     */
27
    public function __construct($signature, Closure $callback)
28
    {
29
        $this->callback = $callback;
30
        $this->signature = $signature;
31
 
32
        parent::__construct();
33
    }
34
 
35
    /**
36
     * Execute the console command.
37
     *
38
     * @param  \Symfony\Component\Console\Input\InputInterface  $input
39
     * @param  \Symfony\Component\Console\Output\OutputInterface  $output
40
     * @return int
41
     */
42
    protected function execute(InputInterface $input, OutputInterface $output)
43
    {
44
        $inputs = array_merge($input->getArguments(), $input->getOptions());
45
 
46
        $parameters = [];
47
 
48
        foreach ((new ReflectionFunction($this->callback))->getParameters() as $parameter) {
49
            if (isset($inputs[$parameter->getName()])) {
50
                $parameters[$parameter->getName()] = $inputs[$parameter->getName()];
51
            }
52
        }
53
 
54
        return (int) $this->laravel->call(
55
            $this->callback->bindTo($this, $this), $parameters
56
        );
57
    }
58
 
59
    /**
60
     * Set the description for the command.
61
     *
62
     * @param  string  $description
63
     * @return $this
64
     */
65
    public function purpose($description)
66
    {
67
        return $this->describe($description);
68
    }
69
 
70
    /**
71
     * Set the description for the command.
72
     *
73
     * @param  string  $description
74
     * @return $this
75
     */
76
    public function describe($description)
77
    {
78
        $this->setDescription($description);
79
 
80
        return $this;
81
    }
82
}