Last active
December 23, 2020 11:22
-
-
Save viktorprogger/1102fbb7880d70fd0f99485bbce72713 to your computer and use it in GitHub Desktop.
Event testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "root/app", | |
"require": { | |
"php": "^7.4", | |
"yiisoft/yii-event": "3.0.x-dev", | |
"yiisoft/di": "3.0.x-dev", | |
"yiisoft/composer-config-plugin": "1.0.x-dev" | |
}, | |
"minimum-stability": "dev", | |
"extra": { | |
"config-plugin": { | |
"console": [ | |
"$common", | |
"$console" | |
], | |
"events-console": "events-console.php" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
return [Message::class => [[EventHandler::class, 'handle']]]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
use Psr\EventDispatcher\EventDispatcherInterface; | |
use Yiisoft\Composer\Config\Builder; | |
use Yiisoft\Di\Container; | |
use Yiisoft\EventDispatcher\Dispatcher\Dispatcher; | |
use Yiisoft\EventDispatcher\Provider\Provider; | |
use Yiisoft\Injector\Injector; | |
use Yiisoft\Yii\Event\ListenerCollectionFactory; | |
require __DIR__ . '/vendor/autoload.php'; | |
final class Message { | |
private ?string $text; | |
public function __construct(?string $text) | |
{ | |
$this->text = $text; | |
} | |
public function getText(): ?string | |
{ | |
return $this->text; | |
} | |
} | |
final class EventHandler { | |
public function handle(Message $message) | |
{ | |
var_dump($message->getText()); | |
} | |
} | |
$container = new Container(require Builder::path('console')); | |
$message = new Message('test message'); | |
$container->get(EventDispatcherInterface::class)->dispatch($message); |
Author
viktorprogger
commented
Dec 23, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment