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
+32-60Lines changed: 32 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,6 @@
1
-
# Console
1
+
# Contributte Console
2
+
3
+
Integration of [Symfony Console](https://symfony.com/doc/current/components/console.html) into Nette Framework.
2
4
3
5
## Content
4
6
@@ -30,7 +32,6 @@ console:
30
32
catchExceptions: true / false
31
33
autoExit: true / false
32
34
url: https://example.com
33
-
lazy: false
34
35
```
35
36
36
37
In SAPI (CLI) mode, there is no HTTP request and thus no URL address.
@@ -43,27 +44,24 @@ console:
43
44
44
45
### Helpers
45
46
46
-
You could also define you custom `helperSet` just in case. There are 2 possible approaches. You can register your
47
-
`App\Model\MyCustomHelperSet` as a service under the `services` section or provide it directly to the extension config `helperSet`.
48
-
49
-
Already defined service:
47
+
You have the option to define your own helperSet if needed. There are two methods to do this. One way is to register your `App\Model\MyCustomHelperSet` as a service in the services section.
48
+
Alternatively, you can directly provide it to the extension configuration helperSet.
50
49
51
50
```neon
52
-
services:
53
-
customHelperSet: App\Model\MyCustomHelperSet
54
-
55
51
console:
56
-
helperSet: @customHelperSet
57
-
```
52
+
# directly
53
+
helperSet: App\Model\MyCustomHelperSet
58
54
59
-
Directly defined helperSet:
55
+
# or reference service
56
+
helperSet: @customHelperSet
60
57
61
-
```neon
62
-
console:
63
-
helperSet: App\Model\MyCustomHelperSet
58
+
services:
59
+
customHelperSet: App\Model\MyCustomHelperSet
64
60
```
65
61
66
-
By default, helperSet contains 4 helpers defined in `Symfony\Component\Console\Application`. You can add more helpers, if need them.
62
+
By default, helperSet contains 4 helpers defined in `Symfony\Component\Console\Application`. You can add your own helpers to the helperSet.
63
+
64
+
```php
67
65
68
66
```neon
69
67
console:
@@ -73,24 +71,17 @@ console:
73
71
74
72
### Lazy-loading
75
73
76
-
From version 3.4 `Symfony\Console` uses command lazy-loading. This extension fully supports this feature and
77
-
you can enable it in the NEON file.
78
-
79
-
```neon
80
-
console:
81
-
lazy: true
82
-
```
83
-
84
-
From this point forward, all commands are instantiated only if needed. Don't forget that listing all commands will instantiate them all.
85
-
86
-
How to define command names? Define `$defaultName` in the command or via the `console.command` tag on the service.
74
+
By default, all commands are registered in the console application during the extension registration. This means that all commands are instantiated and their dependencies are injected.
75
+
This can be a problem if you have a lot of commands and you don't need all of them at once. In this case, this extension setup lazy-loading of commands.
76
+
This means that commands are instantiated only when they are needed.
87
77
88
78
```php
89
79
use Symfony\Component\Console\Command\Command;
80
+
use Symfony\Component\Console\Attribute\AsCommand;
90
81
82
+
#[AsCommand(name: 'app:foo')]
91
83
class FooCommand extends Command
92
84
{
93
-
protected static $defaultName = 'app:foo';
94
85
}
95
86
```
96
87
@@ -116,35 +107,28 @@ use Symfony\Component\Console\Command\Command;
116
107
use Symfony\Component\Console\Input\InputArgument;
117
108
use Symfony\Component\Console\Input\InputInterface;
118
109
use Symfony\Component\Console\Output\OutputInterface;
110
+
use Symfony\Component\Console\Attribute\AsCommand;
119
111
112
+
#[AsCommand(
113
+
name: 'app:foo',
114
+
description: 'Adds user with given username to database',
115
+
)]
120
116
final class AddUserCommand extends Command
121
117
{
122
118
123
-
private UsersModel $usersModel;
119
+
private UserFacade $userFacade;
124
120
125
-
/**
126
-
* Pass dependencies with constructor injection
127
-
*/
128
-
public function __construct(UsersModel $usersModel)
121
+
public function __construct(UserFacade $userFacade)
129
122
{
130
-
parent::__construct(); // don't forget parent call as we extends from Command
131
-
$this->usersModel = $usersModel;
123
+
parent::__construct();
124
+
$this->userFacade = $usersFacade;
132
125
}
133
126
134
127
protected function configure(): void
135
128
{
136
-
// choose command name
137
-
$this->setName('user:add')
138
-
// description (optional)
139
-
->setDescription('Adds user with given username to database')
0 commit comments