16
16
use Nette \DI \Container ;
17
17
use Symfony \Component \Console \Command \Command ;
18
18
use Symfony \Component \Console \Input \ArgvInput ;
19
+ use Symfony \Component \Console \Input \InputDefinition ;
19
20
use Symfony \Component \Console \Input \InputInterface ;
20
21
use Symfony \Component \Console \Input \InputOption ;
21
22
use Symfony \Component \Console \Output \ConsoleOutput ;
@@ -28,9 +29,9 @@ class Application extends \Symfony\Component\Console\Application
28
29
29
30
use \Kdyby \StrictObjects \Scream;
30
31
31
- const CLI_SAPI = 'cli ' ;
32
- const INPUT_ERROR_EXIT_CODE = 253 ;
33
- const INVALID_APP_MODE_EXIT_CODE = 252 ;
32
+ public const CLI_SAPI = 'cli ' ;
33
+ public const INPUT_ERROR_EXIT_CODE = 253 ;
34
+ public const INVALID_APP_MODE_EXIT_CODE = 252 ;
34
35
35
36
/**
36
37
* @var string[]
@@ -46,11 +47,7 @@ class Application extends \Symfony\Component\Console\Application
46
47
*/
47
48
private $ serviceLocator ;
48
49
49
- /**
50
- * @param string $name
51
- * @param string $version
52
- */
53
- public function __construct ($ name = 'Nette Framework ' , $ version = 'UNKNOWN ' )
50
+ public function __construct (string $ name = 'Nette Framework ' , string $ version = 'UNKNOWN ' )
54
51
{
55
52
if ( ! $ version && \class_exists (\Nette \DI \Definitions \ServiceDefinition::class)) {
56
53
$ version = \Kdyby \Console \DI \ConsoleExtension::NETTE_VERSION_30 ;
@@ -65,18 +62,21 @@ public function __construct($name = 'Nette Framework', $version = 'UNKNOWN')
65
62
$ this ->setAutoExit (FALSE );
66
63
}
67
64
68
- public function injectServiceLocator (Container $ sl )
65
+ public function injectServiceLocator (Container $ sl ): void
69
66
{
70
67
$ this ->serviceLocator = $ sl ;
71
68
}
72
69
73
- public function find ($ name )
70
+ /**
71
+ * @param string $name
72
+ */
73
+ public function find ($ name ): Command
74
74
{
75
75
try {
76
76
return parent ::find ($ name );
77
77
78
78
} catch (\InvalidArgumentException $ e ) {
79
- throw new Exception \UnknownCommandException ($ e ->getMessage (), $ e ->getCode (), $ e );
79
+ throw new \ Kdyby \ Console \ Exception \UnknownCommandException ($ e ->getMessage (), $ e ->getCode (), $ e );
80
80
}
81
81
}
82
82
@@ -86,15 +86,15 @@ public function find($name)
86
86
* @return int
87
87
* @throws \Exception
88
88
*/
89
- public function run (InputInterface $ input = NULL , OutputInterface $ output = NULL )
89
+ public function run (? InputInterface $ input = NULL , ? OutputInterface $ output = NULL ): int
90
90
{
91
91
$ input = $ input ?: new ArgvInput ();
92
92
$ output = $ output ?: new ConsoleOutput ();
93
93
94
94
if ($ input ->hasParameterOption ('--debug-mode ' )) {
95
95
if ($ input ->hasParameterOption (['--debug-mode=no ' , '--debug-mode=off ' , '--debug-mode=false ' , '--debug-mode=0 ' ])) {
96
96
if ($ this ->serviceLocator ->parameters ['debugMode ' ]) {
97
- $ this ->renderException (new Exception \InvalidApplicationModeException (
97
+ $ this ->renderException (new \ Kdyby \ Console \ Exception \InvalidApplicationModeException (
98
98
'The app is running in debug mode. You have to use Kdyby\Console\DI\BootstrapHelper in app/bootstrap.php, ' .
99
99
'Kdyby\Console cannot switch already running app to production mode. '
100
100
), $ output );
@@ -104,7 +104,7 @@ public function run(InputInterface $input = NULL, OutputInterface $output = NULL
104
104
105
105
} else {
106
106
if (!$ this ->serviceLocator ->parameters ['debugMode ' ]) {
107
- $ this ->renderException (new Exception \InvalidApplicationModeException (
107
+ $ this ->renderException (new \ Kdyby \ Console \ Exception \InvalidApplicationModeException (
108
108
'The app is running in production mode. You have to use Kdyby\Console\DI\BootstrapHelper in app/bootstrap.php, ' .
109
109
'Kdyby\Console cannot switch already running app to debug mode. '
110
110
), $ output );
@@ -121,9 +121,9 @@ public function run(InputInterface $input = NULL, OutputInterface $output = NULL
121
121
try {
122
122
return parent ::run ($ input , $ output );
123
123
124
- } catch (Exception \UnknownCommandException $ e ) {
124
+ } catch (\ Kdyby \ Console \ Exception \UnknownCommandException $ e ) {
125
125
$ this ->renderException ($ e ->getPrevious (), $ output );
126
- list ( $ message) = explode ("\n" , $ e ->getMessage ());
126
+ [ $ message] = explode ("\n" , $ e ->getMessage ());
127
127
Debugger::log ($ message , Debugger::ERROR );
128
128
129
129
return self ::INPUT_ERROR_EXIT_CODE ;
@@ -156,7 +156,7 @@ public function run(InputInterface $input = NULL, OutputInterface $output = NULL
156
156
* @param \Exception|\Throwable $e
157
157
* @param \Symfony\Component\Console\Output\OutputInterface|NULL $output
158
158
*/
159
- public function handleException ($ e , OutputInterface $ output = NULL )
159
+ public function handleException ($ e , ? OutputInterface $ output = NULL ): void
160
160
{
161
161
$ output = $ output ?: new ConsoleOutput ();
162
162
if ($ e instanceof \Exception) {
@@ -181,7 +181,7 @@ public function handleException($e, OutputInterface $output = NULL)
181
181
}
182
182
}
183
183
184
- protected function doRunCommand (Command $ command , InputInterface $ input , OutputInterface $ output )
184
+ protected function doRunCommand (Command $ command , InputInterface $ input , OutputInterface $ output ): int
185
185
{
186
186
if ($ this ->serviceLocator ) {
187
187
$ this ->serviceLocator ->callInjects ($ command );
@@ -190,7 +190,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
190
190
return parent ::doRunCommand ($ command , $ input , $ output );
191
191
}
192
192
193
- protected function getDefaultInputDefinition ()
193
+ protected function getDefaultInputDefinition (): InputDefinition
194
194
{
195
195
$ definition = parent ::getDefaultInputDefinition ();
196
196
$ definition ->addOption (new InputOption ('--debug-mode ' , NULL , InputOption::VALUE_OPTIONAL , 'Run the application in debug mode? ' ));
0 commit comments