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
+43-36Lines changed: 43 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,3 @@
1
-

2
-
3
1
# Laravel Console Mutex
4
2
5
3
[<imgsrc="https://user-images.githubusercontent.com/1286821/43083932-4915853a-8ea0-11e8-8983-db9e0f04e772.png"alt="Become a Patron"width="160" />](https://patreon.com/dmitryivanov)
protected function initialize(InputInterface $input, OutputInterface $output)
203
205
{
204
206
$this->initializeMutex();
207
+
208
+
parent::initialize($input, $output);
205
209
}
206
210
207
211
// ...
208
212
}
209
213
```
210
214
211
-
If your commandis overriding`initialize` method too, thenyou should call `initializeMutex` method by yourself:
215
+
If your command overrides the`initialize()` method too, you have to call the `initializeMutex()` method by yourself:
212
216
213
217
```php
214
218
class ExampleCommand extends Command
@@ -217,8 +221,10 @@ class ExampleCommand extends Command
217
221
218
222
protected function initialize(InputInterface $input, OutputInterface $output)
219
223
{
224
+
// You have to call it first
220
225
$this->initializeMutex();
221
226
227
+
// Then goes your custom code
222
228
$this->foo = $this->argument('foo');
223
229
$this->bar = $this->argument('bar');
224
230
$this->baz = $this->argument('baz');
@@ -230,9 +236,9 @@ class ExampleCommand extends Command
230
236
231
237
### Several traits conflict?
232
238
233
-
If you're using another `illuminated/console-%` package, then you can find yourself getting into the "traits conflict".
239
+
If you're using another `illuminated/console-%` package, you'll get the "traits conflict" error.
234
240
235
-
For example, if you're trying to build [loggable command](https://github.com/dmitry-ivanov/laravel-console-logger), which is protected against overlapping:
241
+
For example, if you're building a [loggable command](https://github.com/dmitry-ivanov/laravel-console-logger), which doesn't allow overlapping:
236
242
237
243
```php
238
244
class ExampleCommand extends Command
@@ -244,10 +250,10 @@ class ExampleCommand extends Command
244
250
}
245
251
```
246
252
247
-
You'll get the fatal error - the traits conflict, because of both of these traits are overriding `initialize` method:
253
+
You'll get the traits conflict, because both of those traits are overriding the `initialize()` method:
248
254
> If two traits insert a method with the same name, a fatal error is produced, if the conflict is not explicitly resolved.
249
255
250
-
Override `initialize` method by yourself, and initialize traits in required order:
256
+
To fix that - override the `initialize()` method and resolve the conflict:
251
257
252
258
```php
253
259
class ExampleCommand extends Command
@@ -257,6 +263,7 @@ class ExampleCommand extends Command
257
263
258
264
protected function initialize(InputInterface $input, OutputInterface $output)
259
265
{
266
+
// Initialize conflicting traits
260
267
$this->initializeMutex();
261
268
$this->initializeLogging();
262
269
}
@@ -267,6 +274,6 @@ class ExampleCommand extends Command
267
274
268
275
## License
269
276
270
-
The MIT License. Please see [License File](LICENSE.md) for more information.
277
+
Laravel Console Mutex is open-sourced software licensed under the [MIT license](LICENSE.md).
271
278
272
279
[<imgsrc="https://user-images.githubusercontent.com/1286821/43086829-ff7c006e-8ea6-11e8-8b03-ecf97ca95b2e.png"alt="Support on Patreon"width="125" />](https://patreon.com/dmitryivanov)
0 commit comments