feat(core): Implement DDD, CQRS, and Event Sourcing architecture
- 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
This commit is contained in:
29
src/Infrastructure/Router.php
Normal file
29
src/Infrastructure/Router.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace DistributingCarriers\Infrastructure;
|
||||
|
||||
class Router
|
||||
{
|
||||
private $routes = [];
|
||||
|
||||
public function add(string $method, string $path, callable $handler): void
|
||||
{
|
||||
$this->routes[] = [
|
||||
'method' => $method,
|
||||
'path' => $path,
|
||||
'handler' => $handler
|
||||
];
|
||||
}
|
||||
|
||||
public function dispatch(string $method, string $uri)
|
||||
{
|
||||
foreach ($this->routes as $route) {
|
||||
if ($route['method'] === $method && $route['path'] === $uri) {
|
||||
return call_user_func($route['handler']);
|
||||
}
|
||||
}
|
||||
|
||||
http_response_code(404);
|
||||
echo "Not Found";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user