Skip to content

Commit 14cae28

Browse files
committed
ICM: Readme minor fixes.
1 parent 8a4c675 commit 14cae28

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ Prevents overlapping for Laravel console commands.
2121
## Usage
2222

2323
1. Install package through `composer`:
24+
2425
```shell
2526
composer require illuminated/console-mutex
2627
```
2728

2829
2. Use `Illuminated\Console\WithoutOverlapping` trait in your console command class:
30+
2931
```php
3032
namespace App\Console\Commands;
3133
3234
use Illuminate\Console\Command;
3335
use Illuminated\Console\WithoutOverlapping;
3436
35-
class Foo extends Command
37+
class MyProtectedCommand extends Command
3638
{
3739
use WithoutOverlapping;
3840
@@ -59,7 +61,7 @@ If your application is more complex and, for example, is deployed on a several n
5961
You can change mutex strategy by specifying `$mutexStrategy` field:
6062

6163
```php
62-
class Foo extends Command
64+
class MyProtectedCommand extends Command
6365
{
6466
use WithoutOverlapping;
6567
@@ -72,7 +74,7 @@ class Foo extends Command
7274
Or by using `setMutexStrategy` method:
7375

7476
```php
75-
class Foo extends Command
77+
class MyProtectedCommand extends Command
7678
{
7779
use WithoutOverlapping;
7880
@@ -85,15 +87,15 @@ class Foo extends Command
8587
8688
// ...
8789
}
88-
8990
```
9091

9192
## Advanced
9293

9394
Sometimes it is useful to set common mutex for a several commands. You can easily achieve this by setting them the same mutex name.
9495
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+
9597
```php
96-
class Foo extends Command
98+
class MyProtectedCommand extends Command
9799
{
98100
use WithoutOverlapping;
99101
@@ -108,9 +110,10 @@ class Foo extends Command
108110
109111
## Troubleshooting
110112
111-
#### Trait included, but nothing happens?
113+
### Trait included, but nothing happens?
112114
113115
Note, that `WithoutOverlapping` trait is overriding `initialize` method:
116+
114117
```php
115118
trait WithoutOverlapping
116119
{
@@ -124,15 +127,17 @@ trait WithoutOverlapping
124127
```
125128
126129
If your command is overriding `initialize` method too, then you should call `initializeMutex` method by yourself:
130+
127131
```php
128-
class Foo extends Command
132+
class MyProtectedCommand extends Command
129133
{
130134
use WithoutOverlapping;
131135
132136
protected function initialize(InputInterface $input, OutputInterface $output)
133137
{
134138
$this->initializeMutex();
135139
140+
$this->foo = $this->argument('foo');
136141
$this->bar = $this->argument('bar');
137142
$this->baz = $this->argument('baz');
138143
}
@@ -141,12 +146,13 @@ class Foo extends Command
141146
}
142147
```
143148
144-
#### Several traits conflict?
149+
### Several traits conflict?
145150
146151
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+
148154
```php
149-
class Foo extends Command
155+
class MyProtectedCommand extends Command
150156
{
151157
use Loggable;
152158
use WithoutOverlapping;
@@ -159,8 +165,9 @@ You'll get fatal error, the "traits conflict", because both of these traits are
159165
>If two traits insert a method with the same name, a fatal error is produced, if the conflict is not explicitly resolved.
160166

161167
But don't worry, solution is very simple. Override `initialize` method by yourself, and initialize traits in required order:
168+
162169
```php
163-
class Foo extends Command
170+
class MyProtectedCommand extends Command
164171
{
165172
use Loggable;
166173
use WithoutOverlapping;

0 commit comments

Comments
 (0)