Skip to content

Commit c782ee8

Browse files
committed
ICM: Troubleshooting section - more examples.
1 parent 26b6793 commit c782ee8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class Foo extends Command
8383

8484
## Troubleshooting
8585

86+
#### Trait included, but nothing happens?
87+
8688
Note, that `WithoutOverlapping` trait is overriding `initialize` method:
8789
```php
8890
trait WithoutOverlapping
@@ -113,3 +115,37 @@ class Foo extends Command
113115
// ...
114116
}
115117
```
118+
119+
#### Several traits conflict?
120+
121+
If you're using some other cool `illuminated` packages, well, you can find yourself getting "traits conflict".
122+
For example, if you're trying to build [loggable command](https://packagist.org/packages/illuminated/console-logger), which is protected against overlapping:
123+
```php
124+
class Foo extends Command
125+
{
126+
use Loggable;
127+
use WithoutOverlapping;
128+
129+
// ...
130+
}
131+
```
132+
133+
You'll get fatal error here, the "traits conflict", because both of these traits are overriding `initialize` method:
134+
>If two traits insert a method with the same name, a fatal error is produced, if the conflict is not explicitly resolved.
135+
136+
But don't worry, solution is very simple. Just override `initialize` method by yourself, and initialize traits in required order:
137+
```php
138+
class Foo extends Command
139+
{
140+
use Loggable;
141+
use WithoutOverlapping;
142+
143+
protected function initialize(InputInterface $input, OutputInterface $output)
144+
{
145+
$this->initializeMutex();
146+
$this->initializeLogging();
147+
}
148+
149+
// ...
150+
}
151+
```

0 commit comments

Comments
 (0)