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: README.md
+18-11Lines changed: 18 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,18 +21,20 @@ Prevents overlapping for Laravel console commands.
21
21
## Usage
22
22
23
23
1. Install package through `composer`:
24
+
24
25
```shell
25
26
composer require illuminated/console-mutex
26
27
```
27
28
28
29
2. Use `Illuminated\Console\WithoutOverlapping` trait in your console command class:
30
+
29
31
```php
30
32
namespace App\Console\Commands;
31
33
32
34
use Illuminate\Console\Command;
33
35
use Illuminated\Console\WithoutOverlapping;
34
36
35
-
class Foo extends Command
37
+
class MyProtectedCommand extends Command
36
38
{
37
39
use WithoutOverlapping;
38
40
@@ -59,7 +61,7 @@ If your application is more complex and, for example, is deployed on a several n
59
61
You can change mutex strategy by specifying `$mutexStrategy` field:
60
62
61
63
```php
62
-
class Foo extends Command
64
+
class MyProtectedCommand extends Command
63
65
{
64
66
use WithoutOverlapping;
65
67
@@ -72,7 +74,7 @@ class Foo extends Command
72
74
Or by using `setMutexStrategy` method:
73
75
74
76
```php
75
-
class Foo extends Command
77
+
class MyProtectedCommand extends Command
76
78
{
77
79
use WithoutOverlapping;
78
80
@@ -85,15 +87,15 @@ class Foo extends Command
85
87
86
88
// ...
87
89
}
88
-
89
90
```
90
91
91
92
## Advanced
92
93
93
94
Sometimes it is useful to set common mutex for a several commands. You can easily achieve this by setting them the same mutex name.
94
95
By default, mutex name is generated based on a command's name and arguments. To change this, just override `getMutexName` method in your command:
96
+
95
97
```php
96
-
class Foo extends Command
98
+
class MyProtectedCommand extends Command
97
99
{
98
100
use WithoutOverlapping;
99
101
@@ -108,9 +110,10 @@ class Foo extends Command
108
110
109
111
## Troubleshooting
110
112
111
-
#### Trait included, but nothing happens?
113
+
### Trait included, but nothing happens?
112
114
113
115
Note, that `WithoutOverlapping` trait is overriding `initialize` method:
116
+
114
117
```php
115
118
trait WithoutOverlapping
116
119
{
@@ -124,15 +127,17 @@ trait WithoutOverlapping
124
127
```
125
128
126
129
If your command is overriding `initialize` method too, then you should call `initializeMutex` method by yourself:
130
+
127
131
```php
128
-
class Foo extends Command
132
+
class MyProtectedCommand extends Command
129
133
{
130
134
use WithoutOverlapping;
131
135
132
136
protected function initialize(InputInterface $input, OutputInterface $output)
133
137
{
134
138
$this->initializeMutex();
135
139
140
+
$this->foo = $this->argument('foo');
136
141
$this->bar = $this->argument('bar');
137
142
$this->baz = $this->argument('baz');
138
143
}
@@ -141,12 +146,13 @@ class Foo extends Command
141
146
}
142
147
```
143
148
144
-
#### Several traits conflict?
149
+
### Several traits conflict?
145
150
146
151
If you're using some other cool `illuminated/console-%` packages, well, then you can find yourself getting "traits conflict".
147
-
For example, if you're trying to build [loggable command](https://packagist.org/packages/illuminated/console-logger), which is protected against overlapping:
152
+
For example, if you're trying to build [loggable command](https://github.com/dmitry-ivanov/laravel-console-logger), which is protected against overlapping:
153
+
148
154
```php
149
-
class Foo extends Command
155
+
class MyProtectedCommand extends Command
150
156
{
151
157
use Loggable;
152
158
use WithoutOverlapping;
@@ -159,8 +165,9 @@ You'll get fatal error, the "traits conflict", because both of these traits are
159
165
>If two traits insert a method with the same name, a fatal error is produced, if the conflict is not explicitly resolved.
160
166
161
167
But don't worry, solution is very simple. Override `initialize` method by yourself, and initialize traits in required order:
0 commit comments