1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace Venta\Console; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Symfony\Component\Console\Application; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Venta\Contracts\Console\CommandCollector; |
10
|
|
|
use Venta\Contracts\Console\ConsoleApplication as ConsoleApplicationContract; |
11
|
|
|
use Venta\Contracts\Container\Container; |
12
|
|
|
use Venta\Contracts\Kernel\Kernel; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class ConsoleApplication |
17
|
|
|
* |
18
|
|
|
* @package Venta |
19
|
|
|
*/ |
20
|
|
|
class ConsoleApplication extends Application implements ConsoleApplicationContract |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Container |
25
|
|
|
*/ |
26
|
|
|
protected $container; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* HttpApplication constructor. |
31
|
|
|
* |
32
|
|
|
* @param Kernel $kernel |
33
|
|
|
*/ |
34
|
3 |
|
public function __construct(Kernel $kernel) |
35
|
|
|
{ |
36
|
3 |
|
$this->container = $kernel->boot(); |
37
|
|
|
|
38
|
3 |
|
parent::__construct('Venta', $kernel->getVersion()); |
39
|
3 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Passes exception to error handler before rendering to output |
43
|
|
|
* |
44
|
|
|
* @param Exception $e |
45
|
|
|
* @param OutputInterface $output |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
1 |
|
public function renderException(Exception $e, OutputInterface $output) |
49
|
|
|
{ |
50
|
1 |
|
if ($this->container->has('error_handler')) { |
51
|
|
|
/** @var \Whoops\RunInterface $run */ |
52
|
1 |
|
$run = $this->container->get('error_handler'); |
53
|
|
|
// from now on ConsoleApplication will render exception |
54
|
1 |
|
$run->allowQuit(false); |
55
|
1 |
|
$run->writeToOutput(false); |
56
|
|
|
// Ignore the return string, parent call will render exception |
57
|
1 |
|
$run->handleException($e); |
58
|
|
|
} |
59
|
1 |
|
parent::renderException($e, $output); |
60
|
1 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @inheritDoc |
64
|
|
|
*/ |
65
|
1 |
|
final public function run(InputInterface $input = null, OutputInterface $output = null) |
66
|
|
|
{ |
67
|
|
|
/* |
68
|
|
|
|-------------------------------------------------------------------------- |
69
|
|
|
| Bind input |
70
|
|
|
|-------------------------------------------------------------------------- |
71
|
|
|
| |
72
|
|
|
| Rebind input instance, if passed as argument |
73
|
|
|
*/ |
74
|
1 |
|
if ($input) { |
75
|
1 |
|
$this->container->bindInstance(InputInterface::class, $input); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/* |
79
|
|
|
|-------------------------------------------------------------------------- |
80
|
|
|
| Bind output |
81
|
|
|
|-------------------------------------------------------------------------- |
82
|
|
|
| |
83
|
|
|
| Rebind output instance, if passed as argument |
84
|
|
|
*/ |
85
|
1 |
|
if ($output) { |
86
|
1 |
|
$this->container->bindInstance(OutputInterface::class, $output); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/* |
90
|
|
|
|-------------------------------------------------------------------------- |
91
|
|
|
| Add commands |
92
|
|
|
|-------------------------------------------------------------------------- |
93
|
|
|
| |
94
|
|
|
| Add collected commands to application |
95
|
|
|
*/ |
96
|
|
|
/** @var \Venta\Contracts\Console\CommandCollector $collector */ |
97
|
1 |
|
$collector = $this->container->get(CommandCollector::class); |
98
|
1 |
|
$this->addCommands($collector->getCommands()); |
|
|
|
|
99
|
|
|
|
100
|
|
|
/* |
101
|
|
|
|-------------------------------------------------------------------------- |
102
|
|
|
| Run application |
103
|
|
|
|-------------------------------------------------------------------------- |
104
|
|
|
| |
105
|
|
|
| Run console application using bound Input and Output instances |
106
|
|
|
*/ |
107
|
1 |
|
parent::run( |
108
|
1 |
|
$this->container->get(InputInterface::class), |
109
|
1 |
|
$this->container->get(OutputInterface::class) |
110
|
|
|
); |
111
|
1 |
|
} |
112
|
|
|
|
113
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: