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