File tree 2 files changed +24
-4
lines changed
2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -85,8 +85,8 @@ You also need to create the file to run at the command line which creates
85
85
an ``Application `` and adds commands to it::
86
86
87
87
#!/usr/bin/env php
88
- # app/console
89
88
<?php
89
+ // app/console
90
90
91
91
use Acme\DemoBundle\Command\GreetCommand;
92
92
use Symfony\Component\Console\Application;
Original file line number Diff line number Diff line change @@ -43,12 +43,32 @@ it is possible to remove this need by extending the application::
43
43
44
44
return $defaultCommands;
45
45
}
46
+
47
+ /**
48
+ * Overridden so that the application doesn't expect the command
49
+ * name to be the first argument.
50
+ */
51
+ public function getDefinition()
52
+ {
53
+ $inputDefinition = parent::getDefinition();
54
+ // clear out the normal first argument, which is the command name
55
+ $inputDefinition->setArguments();
56
+
57
+ return $inputDefinition;
58
+ }
46
59
}
47
60
48
61
When calling your console script, the command `MyCommand ` will then always
49
62
be used, without having to pass its name.
50
63
51
- .. note ::
64
+ You can also simplify how you execute the application::
65
+
66
+ #!/usr/bin/env php
67
+ <?php
68
+ // command.php
69
+
70
+ use Acme\Tool\MyApplication;
71
+
72
+ $application = new MyApplication();
73
+ $application->run();
52
74
53
- If your command accepts one or more arguments, you may also want to override
54
- the :method: `Symfony\\ Component\\ Console\\ getDefaultInputDefinition ` method.
You can’t perform that action at this time.
0 commit comments