acc-create-mediator
Mediator Pattern Generator
Overview
Generates Mediator pattern components for PHP 8.5 to coordinate complex interactions between multiple objects without them referencing each other directly.
When to Use
- Complex communication between multiple objects
- Reducing coupling in event-driven systems
- Coordinating UI components or form elements
- Command bus / Query bus implementation
- Chat room / notification hub scenarios
- Workflow coordination
Generated Components
| Component | Location | Purpose |
|---|---|---|
| MediatorInterface | src/Application/{Context}/Mediator/ |
Defines mediation contract |
| ConcreteMediator | src/Application/{Context}/Mediator/ |
Implements coordination logic |
| ColleagueInterface | src/Application/{Context}/Mediator/Colleague/ |
Participant contract |
| AbstractColleague | src/Application/{Context}/Mediator/Colleague/ |
Base with mediator access |
| ConcreteColleagues | src/Application/{Context}/Mediator/Colleague/ |
Participating components |
| Tests | tests/{Context}/Application/Mediator/ |
Unit tests |
Input Requirements
- Name - Mediator name (e.g., "OrderWorkflow", "ChatRoom")
- Context - Bounded context (e.g., "Order", "Notification")
- Colleagues - List of participating components
- Events - Events to coordinate (optional)
Template: Mediator Interface
<?php
declare(strict_types=1);
namespace App\{Context}\Application\Mediator;
use App\{Context}\Application\Mediator\Colleague\ColleagueInterface;
interface {Name}Mediator
{
public function notify(ColleagueInterface $sender, string $event, mixed $data = null): void;
public function register(ColleagueInterface $colleague): void;
public function send(string $request, mixed $data = null): mixed;
}
Template: Colleague Interface
<?php
declare(strict_types=1);
namespace App\{Context}\Application\Mediator\Colleague;
use App\{Context}\Application\Mediator\{Name}Mediator;
interface ColleagueInterface
{
public function getName(): string;
public function setMediator({Name}Mediator $mediator): void;
public function handle(mixed $data): mixed;
}
Template: Abstract Colleague
<?php
declare(strict_types=1);
namespace App\{Context}\Application\Mediator\Colleague;
use App\{Context}\Application\Mediator\{Name}Mediator;
abstract class AbstractColleague implements ColleagueInterface
{
protected ?{Name}Mediator $mediator = null;
public function setMediator({Name}Mediator $mediator): void
{
$this->mediator = $mediator;
}
protected function notify(string $event, mixed $data = null): void
{
if ($this->mediator === null) {
throw new MediatorNotSetException();
}
$this->mediator->notify($this, $event, $data);
}
protected function send(string $request, mixed $data = null): mixed
{
if ($this->mediator === null) {
throw new MediatorNotSetException();
}
return $this->mediator->send($request, $data);
}
}
File Placement
src/
└── {Context}/
└── Application/
└── Mediator/
├── {Name}Mediator.php # Interface
├── {Name}MediatorImpl.php # Implementation
└── Colleague/
├── ColleagueInterface.php # Base interface
├── AbstractColleague.php # Base class
└── {Colleague}.php # Participants
tests/
└── {Context}/
└── Application/
└── Mediator/
└── {Name}MediatorTest.php # Tests
GRASP Compliance
| Principle | Implementation |
|---|---|
| Low Coupling | Colleagues don't know each other |
| Indirection | Mediator provides indirection layer |
| Controller | Mediator coordinates use case flow |
| Pure Fabrication | Mediator is artificial coordinating class |
References
See references/ for detailed documentation:
templates.md- Full Mediator, Colleague, Command Bus, Event Mediator, Chat Room templatesexamples.md- Real-world examples
More from dykyi-roman/awesome-claude-code
psr-overview-knowledge
PHP Standards Recommendations (PSR) overview knowledge base. Provides comprehensive reference for all accepted PSRs including PSR-1,3,4,6,7,11,12,13,14,15,16,17,18,20. Use for PSR selection decisions and compliance audits.
22detect-code-smells
Detects code smells in PHP codebases. Identifies God Class, Feature Envy, Data Clumps, Long Parameter List, Long Method, Primitive Obsession, Message Chains, Inappropriate Intimacy. Generates actionable reports with refactoring recommendations.
15clean-arch-knowledge
Clean Architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Clean Architecture and Hexagonal Architecture audits.
15ddd-knowledge
DDD architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Domain-Driven Design audits.
14testing-knowledge
Testing knowledge base for PHP 8.4 projects. Provides testing pyramid, AAA pattern, naming conventions, isolation principles, DDD testing guidelines, and PHPUnit patterns.
12bug-root-cause-finder
Root cause analysis methods for PHP bugs. Provides 5 Whys technique, fault tree analysis, git bisect guidance, and stack trace parsing.
12