deviouspk /
larapi
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Created by PhpStorm. |
||
| 4 | * User: arthur |
||
| 5 | * Date: 11.03.19 |
||
| 6 | * Time: 17:08 |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace Foundation\Traits; |
||
| 10 | |||
| 11 | use Foundation\Generator\Abstracts\ResourceGeneratedEvent; |
||
| 12 | use Foundation\Generator\Contracts\ResourceGenerationContract; |
||
| 13 | use Illuminate\Support\Facades\Event; |
||
| 14 | |||
| 15 | trait DispatchedEvents |
||
| 16 | { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param string $class |
||
| 20 | * @return ResourceGeneratedEvent[] |
||
| 21 | */ |
||
| 22 | 26 | protected function getDispatchedEvents(?string $class): array |
|
| 23 | { |
||
| 24 | 26 | $events = []; |
|
| 25 | Event::assertDispatched($class, function ($event) use (&$events) { |
||
| 26 | 26 | $events[] = $event; |
|
| 27 | 26 | return true; |
|
| 28 | 26 | }); |
|
| 29 | 26 | return $events; |
|
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param string $class |
||
| 34 | * @return ResourceGenerationContract |
||
| 35 | */ |
||
| 36 | 26 | protected function getFirstDispatchedEvent(?string $class): ResourceGenerationContract |
|
| 37 | { |
||
| 38 | 26 | $events = $this->getDispatchedEvents($class); |
|
| 39 | 26 | if (empty($events)) |
|
| 40 | return null; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 41 | 26 | return $events[0]; |
|
| 42 | } |
||
| 43 | } |
||
| 44 |