@@ -45,12 +45,26 @@ want a command to create a user::
45
45
46
46
protected function execute(InputInterface $input, OutputInterface $output)
47
47
{
48
- // ...
48
+ // ... put here the code to run in your command
49
+
50
+ // this method must return an integer number with the "exit status code"
51
+ // of the command. You can also use these constants to make code more readable
52
+
53
+ // return this if there was no problem running the command
54
+ // (it's equivalent to returning int(0))
55
+ return Command::SUCCESS;
49
56
50
- return 0;
57
+ // or return this if some error happened during the execution
58
+ // (it's equivalent to returning int(1))
59
+ // return Command::FAILURE;
51
60
}
52
61
}
53
62
63
+ .. versionadded :: 5.1
64
+
65
+ The ``Command::SUCCESS `` and ``Command::FAILURE `` constants were introduced
66
+ in Symfony 5.1.
67
+
54
68
Configuring the Command
55
69
-----------------------
56
70
@@ -149,7 +163,7 @@ the console::
149
163
$output->write('You are about to ');
150
164
$output->write('create a user.');
151
165
152
- return 0 ;
166
+ return Command::SUCCESS ;
153
167
}
154
168
155
169
Now, try executing the command:
@@ -200,7 +214,7 @@ which returns an instance of
200
214
$section1->clear(2);
201
215
// Output is now completely empty!
202
216
203
- return 0 ;
217
+ return Command::SUCCESS ;
204
218
}
205
219
}
206
220
@@ -242,7 +256,7 @@ Use input options or arguments to pass information to the command::
242
256
// retrieve the argument value using getArgument()
243
257
$output->writeln('Username: '.$input->getArgument('username'));
244
258
245
- return 0 ;
259
+ return Command::SUCCESS ;
246
260
}
247
261
248
262
Now, you can pass the username to the command:
@@ -293,7 +307,7 @@ as a service, you can use normal dependency injection. Imagine you have a
293
307
294
308
$output->writeln('User successfully generated!');
295
309
296
- return 0 ;
310
+ return Command::SUCCESS ;
297
311
}
298
312
}
299
313
0 commit comments