yiisoft /
yii-demo
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace App\Widget; |
||
| 6 | |||
| 7 | use Yiisoft\Session\Flash\FlashInterface; |
||
| 8 | use Yiisoft\Yii\Bootstrap5\Alert; |
||
| 9 | use Yiisoft\Widget\Widget; |
||
| 10 | |||
| 11 | final class FlashMessage extends Widget |
||
| 12 | { |
||
| 13 | private FlashInterface $flash; |
||
| 14 | |||
| 15 | 6 | public function __construct(FlashInterface $flash) |
|
| 16 | { |
||
| 17 | 6 | $this->flash = $flash; |
|
| 18 | 6 | } |
|
| 19 | |||
| 20 | 6 | public function run(): string |
|
| 21 | { |
||
| 22 | 6 | $flashes = $this->flash->getAll(); |
|
| 23 | |||
| 24 | 6 | $html = []; |
|
| 25 | 6 | foreach ($flashes as $type => $data) { |
|
| 26 | 2 | foreach ($data as $message) { |
|
| 27 | 2 | $html[] = Alert::widget() |
|
| 28 | 2 | ->options(['class' => "alert-{$type} shadow"]) |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 29 | 2 | ->body($message['body']) |
|
| 30 | ; |
||
| 31 | } |
||
| 32 | } |
||
| 33 | |||
| 34 | 6 | return implode($html); |
|
| 35 | } |
||
| 36 | } |
||
| 37 |