@@ -47,10 +47,18 @@ want a command to create a user::
47
47
{
48
48
// ...
49
49
50
- return 0;
50
+ return Command::SUCCESS;
51
+
52
+ // or return this if some error happened during the execution:
53
+ // return Command::FAILURE;
51
54
}
52
55
}
53
56
57
+ .. versionadded :: 5.1
58
+
59
+ The ``Command::SUCCESS `` and ``Command::FAILURE `` constants were introduced
60
+ in Symfony 5.1.
61
+
54
62
Configuring the Command
55
63
-----------------------
56
64
@@ -149,7 +157,7 @@ the console::
149
157
$output->write('You are about to ');
150
158
$output->write('create a user.');
151
159
152
- return 0 ;
160
+ return Command::SUCCESS ;
153
161
}
154
162
155
163
Now, try executing the command:
@@ -200,7 +208,7 @@ which returns an instance of
200
208
$section1->clear(2);
201
209
// Output is now completely empty!
202
210
203
- return 0 ;
211
+ return Command::SUCCESS ;
204
212
}
205
213
}
206
214
@@ -242,7 +250,7 @@ Use input options or arguments to pass information to the command::
242
250
// retrieve the argument value using getArgument()
243
251
$output->writeln('Username: '.$input->getArgument('username'));
244
252
245
- return 0 ;
253
+ return Command::SUCCESS ;
246
254
}
247
255
248
256
Now, you can pass the username to the command:
@@ -293,7 +301,7 @@ as a service, you can use normal dependency injection. Imagine you have a
293
301
294
302
$output->writeln('User successfully generated!');
295
303
296
- return 0 ;
304
+ return Command::SUCCESS ;
297
305
}
298
306
}
299
307
0 commit comments