PHP code example of componenta / cqrs-app

1. Go to this page and download the library: Download componenta/cqrs-app 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/ */

    

componenta / cqrs-app example snippets


return [
    new \Componenta\App\ConfigProvider(),
    new \Componenta\App\Console\ConfigProvider(),
    new \Componenta\CQRS\ConfigProvider(),
    new \Componenta\CQRS\App\ConfigProvider(),
    new ApplicationConfigProvider(),
];

use Componenta\CQRS\Command\Attribute\AsCommandHandler;

final readonly class PublishPost
{
    public function __construct(public int $id) {}
}

#[AsCommandHandler]
final class PublishPostHandler
{
    public function __invoke(PublishPost $command): string
    {
        return 'published:' . $command->id;
    }
}

use Componenta\CQRS\Command\Attribute\AsCommandListener;
use Componenta\CQRS\Command\Event\CommandFailedEvent;
use Componenta\CQRS\Command\Event\CommandListenerInterface;
use Componenta\CQRS\Command\Event\CommandProcessedEvent;
use Componenta\CQRS\Command\Event\CommandProcessEvent;

#[AsCommandListener(PublishPost::class, priority: 10, eventTypes: [CommandProcessedEvent::class])]
final class PublishPostListener implements CommandListenerInterface
{
    public function handleEvent(CommandProcessEvent|CommandProcessedEvent|CommandFailedEvent $event): void
    {
        // React to successful publication.
    }
}

return [
    'command_handlers' => [],
    'query_handlers' => [],
    'command_listeners' => [],
];
bash
php bin/console.php app:build