You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: .docs/README.md
+55-12
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
-[Setup](#usage)
6
6
-[Configuration](#configuration)
7
-
-[Example command](#command)
7
+
-[Example command](#example-command)
8
8
-[Entrypoint](#entrypoint)
9
9
10
10
## Setup
@@ -29,15 +29,16 @@ console:
29
29
version: '1.0'
30
30
catchExceptions: true / false
31
31
autoExit: true / false
32
-
url: https://contributte.org
32
+
url: https://example.com
33
33
lazy: false
34
34
```
35
35
36
-
In SAPI (CLI) mode there is no http request and thus no URL address. This is an inconvenience you have to solve by yourself - via the `console.url` option.
36
+
In SAPI (CLI) mode, there is no HTTP request and thus no URL address.
37
+
You have to set base URL on your own so that link generator works. Use `console.url` option:
37
38
38
39
```neon
39
40
console:
40
-
url: https://contributte.org
41
+
url: https://example.com
41
42
```
42
43
43
44
### Helpers
@@ -102,29 +103,71 @@ services:
102
103
tags: [console.command: app:foo]
103
104
```
104
105
105
-
## Command
106
+
## Example command
106
107
107
-
### Create command
108
+
In case of having `console.php` as entrypoint (see below), this would add a user with username `john.doe` to database:
108
109
109
-
```php
110
+
> `php console.php user:add john.doe`
110
111
112
+
```php
111
113
namespace App\Console;
112
114
113
115
use Symfony\Component\Console\Command\Command;
116
+
use Symfony\Component\Console\Input\InputArgument;
114
117
use Symfony\Component\Console\Input\InputInterface;
115
118
use Symfony\Component\Console\Output\OutputInterface;
116
119
117
-
final class FooCommand extends Command
120
+
final class AddUserCommand extends Command
118
121
{
119
122
123
+
private UsersModel $usersModel;
124
+
125
+
/**
126
+
* Pass dependencies with constructor injection
127
+
*/
128
+
public function __construct(UsersModel $usersModel)
129
+
{
130
+
parent::__construct(); // don't forget parent call as we extends from Command
131
+
$this->usersModel = $usersModel;
132
+
}
133
+
120
134
protected function configure(): void
121
135
{
122
-
$this->setName('foo');
136
+
// choose command name
137
+
$this->setName('user:add')
138
+
// description (optional)
139
+
->setDescription('Adds user with given username to database')
0 commit comments