Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
"command": "composer require --dev --ignore-platform-reqs phpstan/phpstan && vendor/bin/phpstan analyse"
}
}
],
"backwardCompatibilityCheck": true
]
}
111 changes: 107 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,109 @@
# cmd-bus
# cmd-bus Documentation

Command Bus for Mezzio applications
A Command Bus implementation for Mezzio applications, providing a clean way to handle commands through a middleware pipeline.

This package is inspired by and borrows heavily from the laminas stratigility and mezzio packages.
It may or may not eventually be released. We'll see.
## Table of Contents

### Core Components

- [CmdBus](docs/cmdbus.md) - The main command bus implementation
- [CmdBusInterface](docs/cmdbus-interface.md) - Command bus contract
- [MiddlewarePipe](docs/middleware-pipe.md) - Middleware pipeline management
- [MiddlewarePipelineInterface](docs/middleware-pipeline-interface.md) - Pipeline contract
- [CommandHandlerFactory](docs/command-handler-factory.md) - Factory for command handlers
- [ConfigProvider](docs/config-provider.md) - Laminas configuration provider
- [Next](docs/next.md) - Pipeline delegation helper

### Interfaces

- [CommandInterface](docs/command-interface.md) - Command contract
- [CommandHandlerInterface](docs/command-handler-interface.md) - Handler contract
- [MiddlewareInterface](docs/middleware-interface.md) - Middleware contract

### Container Factories

- [CmdBusFactory](docs/container/cmdbus-factory.md) - Service factory for CmdBus
- [CommandHandlerFactoryFactory](docs/container/command-handler-factory-factory.md) - Factory for CommandHandlerFactory
- [CommandHandlerMiddlewareFactory](docs/container/command-handler-middleware-factory.md) - Factory for CommandHandlerMiddleware
- [MiddlewarePipeFactory](docs/container/middleware-pipe-factory.md) - Factory for MiddlewarePipe

### Middleware

- [PreCommandHandlerMiddleware](docs/middleware/pre-command-handler-middleware.md) - Middleware for pre-processing commands
- [CommandHandlerMiddleware](docs/middleware/command-handler-middleware.md) - Final middleware for command execution
- [PostCommandHandlerMiddleware](docs/middleware/post-command-handler-middleware.md) - Middleware for post-processing results

### Handlers

- [EmptyPipelineHandler](docs/handler/empty-pipeline-handler.md) - Default handler for empty pipelines

### Exceptions

- [CommandException](docs/exception/command-exception.md) - Base command exception
- [InvalidConfigurationException](docs/exception/invalid-configuration-exception.md) - Configuration errors
- [NextHandlerAlreadyCalledException](docs/exception/next-handler-already-called-exception.md) - Pipeline state errors
- [ServiceNotFoundException](docs/exception/service-not-found-exception.md) - Service resolution errors

## Quick Start

### Installation

```bash
composer require php-cmd/cmd-bus
```

### Basic Configuration

```php
// config/config.php
return [
PhpCmd\CmdBus\ConfigProvider::class => [
'command-map' => [
App\Command\CreateUserCommand::class => App\Handler\CreateUserHandler::class,
],
'middleware_pipeline' => [
['middleware' => \PhpCmd\CmdBus\Middleware\CommandHandlerMiddleware::class, 'priority' => 1],
],
],
];
```

### Usage in Mezzio

```php
// In a request handler or middleware
class UserHandler
{
public function __construct(
private \PhpCmd\CmdBus\CmdBusInterface $commandBus
) {}

public function handle(ServerRequestInterface $request): ResponseInterface
{
$data = $request->getParsedBody();

$command = new CreateUserCommand(
email: $data['email'],
username: $data['username']
);

$user = $this->commandBus->handle($command);

return new JsonResponse(['user' => $user->toArray()]);
}
}
```

## Architecture Overview

The cmd-bus library follows these key principles:

1. **Commands** are data objects that implement `CommandInterface`
2. **Handlers** process commands and implement `CommandHandlerInterface`
3. **Middleware** can intercept and potentially modify command processing
4. **Pipeline** manages middleware execution order
5. **Factory classes** integrate with Laminas ServiceManager/ Psr\Container\ContainerInterface

## Contributing

See the project repository for contribution guidelines and development setup instructions.
109 changes: 0 additions & 109 deletions docs/README.md

This file was deleted.