1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ElfSundae\Console; |
4
|
|
|
|
5
|
|
|
use Closure; |
6
|
|
|
use Illuminate\Support\Arr; |
7
|
|
|
use Illuminate\Container\Container; |
8
|
|
|
use Symfony\Component\Console\Command\Command; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Illuminate\Events\Dispatcher as EventsDispatcher; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Illuminate\Console\Application as LaravelApplication; |
13
|
|
|
|
14
|
|
|
class Application extends LaravelApplication |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Create a new console application. |
18
|
|
|
* |
19
|
|
|
* @param string $name |
20
|
|
|
* @param string $version |
21
|
|
|
*/ |
22
|
3 |
|
public function __construct($name = 'Console Application', $version = '1.0.0') |
23
|
|
|
{ |
24
|
3 |
|
parent::__construct($laravel = new Container, new EventsDispatcher($laravel), $version); |
25
|
|
|
|
26
|
3 |
|
$this->setName($name); |
27
|
3 |
|
$this->setAutoExit(true); |
28
|
3 |
|
$this->setCatchExceptions(true); |
29
|
3 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Register a Closure based command. |
33
|
|
|
* |
34
|
|
|
* @param string $signature |
35
|
|
|
* @param \Closure $callback |
36
|
|
|
* @param string $description |
37
|
|
|
* @return \ElfSundae\Console\ClosureCommand |
38
|
|
|
*/ |
39
|
1 |
|
public function command($signature, Closure $callback, $description = null) |
40
|
|
|
{ |
41
|
1 |
|
return $this->add( |
42
|
1 |
|
(new ClosureCommand($signature, $callback))->describe($description) |
43
|
1 |
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Run the current application as a single command application. |
48
|
|
|
* |
49
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface|null $input |
50
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface|null $output |
51
|
|
|
* @return int |
52
|
|
|
*/ |
53
|
1 |
|
public function runAsSingle(InputInterface $input = null, OutputInterface $output = null) |
54
|
|
|
{ |
55
|
|
|
if ($command = Arr::last($this->all())) { |
56
|
1 |
|
$this->setDefaultCommand($command->getName(), true); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $this->run($input, $output); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|