@@ -35,7 +35,7 @@ Creating a basic Command
35
35
To make a console command that greets you from the command line, create ``GreetCommand.php ``
36
36
and add the following to it::
37
37
38
- namespace Acme\DemoBundle\ Command;
38
+ namespace Acme\Command;
39
39
40
40
use Symfony\Component\Console\Command\Command;
41
41
use Symfony\Component\Console\Input\InputArgument;
@@ -86,9 +86,9 @@ an ``Application`` and adds commands to it::
86
86
87
87
#!/usr/bin/env php
88
88
<?php
89
- // app/console
89
+ // application.php
90
90
91
- use Acme\DemoBundle\ Command\GreetCommand;
91
+ use Acme\Command\GreetCommand;
92
92
use Symfony\Component\Console\Application;
93
93
94
94
$application = new Application();
@@ -99,7 +99,7 @@ Test the new console command by running the following
99
99
100
100
.. code-block :: bash
101
101
102
- $ app/console demo:greet Fabien
102
+ $ php application.php demo:greet Fabien
103
103
104
104
This will print the following to the command line:
105
105
@@ -111,7 +111,7 @@ You can also use the ``--yell`` option to make everything uppercase:
111
111
112
112
.. code-block :: bash
113
113
114
- $ app/console demo:greet Fabien --yell
114
+ $ php application.php demo:greet Fabien --yell
115
115
116
116
This prints::
117
117
@@ -267,8 +267,8 @@ The command can now be used in either of the following ways:
267
267
268
268
.. code-block :: bash
269
269
270
- $ app/console demo:greet Fabien
271
- $ app/console demo:greet Fabien Potencier
270
+ $ php application.php demo:greet Fabien
271
+ $ php application.php demo:greet Fabien Potencier
272
272
273
273
It is also possible to let an argument take a list of values (imagine you want
274
274
to greet all your friends). For this it must be specified at the end of the
@@ -286,7 +286,7 @@ To use this, just specify as many names as you want:
286
286
287
287
.. code-block :: bash
288
288
289
- $ app/console demo:greet Fabien Ryan Bernhard
289
+ $ php application.php demo:greet Fabien Ryan Bernhard
290
290
291
291
You can access the ``names `` argument as an array::
292
292
@@ -356,8 +356,8 @@ flag:
356
356
357
357
.. code-block :: bash
358
358
359
- $ app/console demo:greet Fabien
360
- $ app/console demo:greet Fabien --iterations=5
359
+ $ php application.php demo:greet Fabien
360
+ $ php application.php demo:greet Fabien --iterations=5
361
361
362
362
The first example will only print once, since ``iterations `` is empty and
363
363
defaults to ``1 `` (the last argument of ``addOption ``). The second example
@@ -368,8 +368,8 @@ will work:
368
368
369
369
.. code-block :: bash
370
370
371
- $ app/console demo:greet Fabien --iterations=5 --yell
372
- $ app/console demo:greet Fabien --yell --iterations=5
371
+ $ php application.php demo:greet Fabien --iterations=5 --yell
372
+ $ php application.php demo:greet Fabien --yell --iterations=5
373
373
374
374
There are 4 option variants you can use:
375
375
@@ -415,9 +415,9 @@ useful one is the :class:`Symfony\\Component\\Console\\Tester\\CommandTester`
415
415
class. It uses special input and output classes to ease testing without a real
416
416
console::
417
417
418
+ use Acme\Command\GreetCommand;
418
419
use Symfony\Component\Console\Application;
419
420
use Symfony\Component\Console\Tester\CommandTester;
420
- use Acme\DemoBundle\Command\GreetCommand;
421
421
422
422
class ListCommandTest extends \PHPUnit_Framework_TestCase
423
423
{
@@ -444,9 +444,9 @@ You can test sending arguments and options to the command by passing them
444
444
as an array to the :method: `Symfony\\ Component\\ Console\\ Tester\\ CommandTester::execute `
445
445
method::
446
446
447
+ use Acme\Command\GreetCommand;
447
448
use Symfony\Component\Console\Application;
448
449
use Symfony\Component\Console\Tester\CommandTester;
449
- use Acme\DemoBundle\Command\GreetCommand;
450
450
451
451
class ListCommandTest extends \PHPUnit_Framework_TestCase
452
452
{
@@ -527,6 +527,7 @@ Learn More!
527
527
* :doc: `/components/console/usage `
528
528
* :doc: `/components/console/single_command_tool `
529
529
* :doc: `/components/console/changing_default_command `
530
+ * :doc: `/components/console/events `
530
531
531
532
.. _Packagist : https://packagist.org/packages/symfony/console
532
533
.. _ANSICON : https://github.com./adoxa/ansicon/downloads
0 commit comments