- Add project README and Composer configuration with PSR-4 autoloading - Implement domain layer with AggregateRoot base class for event sourcing - Create Carrier aggregate with CarrierRegistered domain event - Add application layer with RegisterCarrierCommand and RegisterCarrierHandler - Implement infrastructure layer with EventStore interface and CassandraEventStore - Add CommandBus and Router for request handling and routing - Create demo test file to showcase carrier registration workflow - Establish foundation for event-driven architecture with Cassandra persistence
67 lines
2.0 KiB
PHP
67 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Cassandra {
|
|
class Timestamp
|
|
{
|
|
}
|
|
}
|
|
|
|
namespace {
|
|
// Mock Cassandra Session
|
|
class MockCassandraSession
|
|
{
|
|
public $executedStatements = [];
|
|
|
|
public function prepare($cql)
|
|
{
|
|
return new MockStatement($cql);
|
|
}
|
|
|
|
public function execute($statement, $options)
|
|
{
|
|
$this->executedStatements[] = [
|
|
'statement' => $statement->cql,
|
|
'arguments' => $options['arguments']
|
|
];
|
|
echo "Executed CQL: " . $statement->cql . "\n";
|
|
return [];
|
|
}
|
|
}
|
|
|
|
class MockStatement
|
|
{
|
|
public $cql;
|
|
public function __construct($cql)
|
|
{
|
|
$this->cql = $cql;
|
|
}
|
|
}
|
|
|
|
require_once __DIR__ . '/../src/Infrastructure/EventStore.php';
|
|
require_once __DIR__ . '/../src/Infrastructure/CassandraEventStore.php';
|
|
require_once __DIR__ . '/../src/Infrastructure/CommandBus.php';
|
|
require_once __DIR__ . '/../src/Domain/AggregateRoot.php';
|
|
require_once __DIR__ . '/../src/Domain/Events/CarrierRegistered.php';
|
|
require_once __DIR__ . '/../src/Domain/Carrier.php';
|
|
require_once __DIR__ . '/../src/Application/Commands/RegisterCarrierCommand.php';
|
|
require_once __DIR__ . '/../src/Application/Handlers/RegisterCarrierHandler.php';
|
|
|
|
use DistributingCarriers\Infrastructure\CommandBus;
|
|
use DistributingCarriers\Infrastructure\CassandraEventStore;
|
|
use DistributingCarriers\Application\Commands\RegisterCarrierCommand;
|
|
use DistributingCarriers\Application\Handlers\RegisterCarrierHandler;
|
|
|
|
echo "Starting Demo...\n";
|
|
|
|
$session = new MockCassandraSession();
|
|
$eventStore = new CassandraEventStore($session);
|
|
$commandBus = new CommandBus();
|
|
|
|
$commandBus->register(RegisterCarrierCommand::class, new RegisterCarrierHandler($eventStore));
|
|
|
|
$command = new RegisterCarrierCommand("Demo Carrier", "demo@example.com");
|
|
$commandBus->dispatch($command);
|
|
|
|
echo "Demo Completed.\n";
|
|
}
|