@@ -22,95 +22,31 @@ You can install the component in 2 different ways:
22
22
23
23
.. include :: /components/require_autoload.rst.inc
24
24
25
- Creating a basic Command
26
- ------------------------
27
-
28
- To make a console command that greets you from the command line, create ``GreetCommand.php ``
29
- and add the following to it::
30
-
31
- namespace Acme\Console\Command;
32
-
33
- use Symfony\Component\Console\Command\Command;
34
- use Symfony\Component\Console\Input\InputArgument;
35
- use Symfony\Component\Console\Input\InputInterface;
36
- use Symfony\Component\Console\Input\InputOption;
37
- use Symfony\Component\Console\Output\OutputInterface;
38
-
39
- class GreetCommand extends Command
40
- {
41
- protected function configure()
42
- {
43
- $this
44
- ->setName('demo:greet')
45
- ->setDescription('Greet someone')
46
- ->addArgument(
47
- 'name',
48
- InputArgument::OPTIONAL,
49
- 'Who do you want to greet?'
50
- )
51
- ->addOption(
52
- 'yell',
53
- null,
54
- InputOption::VALUE_NONE,
55
- 'If set, the task will yell in uppercase letters'
56
- )
57
- ;
58
- }
59
-
60
- protected function execute(InputInterface $input, OutputInterface $output)
61
- {
62
- $name = $input->getArgument('name');
63
- if ($name) {
64
- $text = 'Hello '.$name;
65
- } else {
66
- $text = 'Hello';
67
- }
68
-
69
- if ($input->getOption('yell')) {
70
- $text = strtoupper($text);
71
- }
72
-
73
- $output->writeln($text);
74
- }
75
- }
76
-
77
- You also need to create the file to run at the command line which creates
78
- an ``Application `` and adds commands to it::
25
+ Creating an Application File
26
+ ----------------------------
27
+
28
+ At first, you need to create a file to run commands from the console::
79
29
80
30
#!/usr/bin/env php
81
31
<?php
82
32
// application.php
83
33
84
34
require __DIR__.'/vendor/autoload.php';
85
35
86
- use Acme\Console\Command\GreetCommand;
87
36
use Symfony\Component\Console\Application;
88
37
89
38
$application = new Application();
90
- $application->add(new GreetCommand());
91
- $application->run();
92
-
93
- Test the new console command by running the following
94
-
95
- .. code-block :: bash
96
-
97
- $ php application.php demo:greet Fabien
98
39
99
- This will print the following to the command line:
40
+ // ... register commands
100
41
101
- .. code-block :: text
102
-
103
- Hello Fabien
104
-
105
- You can also use the ``--yell `` option to make everything uppercase:
106
-
107
- .. code-block :: bash
108
-
109
- $ php application.php demo:greet Fabien --yell
42
+ $application->run();
110
43
111
- This prints::
44
+ See the :doc: `/console ` article for information about how to create commands.
45
+ You can register the commands using
46
+ :method: `Symfony\\ Component\\ Console\\ Application::add `::
112
47
113
- HELLO FABIEN
48
+ // ...
49
+ $application->add(new GenerateAdminCommand());
114
50
115
51
Learn More
116
52
----------
@@ -119,7 +55,8 @@ Learn More
119
55
:maxdepth: 1
120
56
:glob:
121
57
122
- console/*
123
- console/helpers/index
58
+ /console
59
+ /components/console/*
60
+ /components/console/helpers/index
124
61
125
62
.. _Packagist : https://packagist.org/packages/symfony/console
0 commit comments