PHP code example of open-solid / domain
1. Go to this page and download the library: Download open-solid/domain library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
open-solid / domain example snippets
use OpenSolid\Bus\Handler\MessageHandlersLocator;
use OpenSolid\Bus\Middleware\HandlingMiddleware;
use OpenSolid\Bus\NativeLazyMessageBus;
use OpenSolid\Bus\NativeMessageBus;
use OpenSolid\DomainEvent\Bus\NativeDomainEventBus;
use OpenSolid\DomainEvent\DomainEvent;
final readonly class UserRegistered extends DomainEvent
{
}
final readonly class UserRegisteredSubscriber
{
public function __invoke(UserRegistered $event): void
{
// Handle the event
}
}
$nativeMessageBus = new NativeMessageBus([
new HandlingMiddleware(
new MessageHandlersLocator([
UserRegistered::class => [new UserRegisteredSubscriber()],
]),
),
]);
$bus = new NativeDomainEventBus(new NativeLazyMessageBus($nativeMessageBus));
$bus->publish(new EntityUpdated('uuid'));
// do something in between ...
$bus->flush();