Claude-skill-registry acc-create-mediator
Generates Mediator pattern for PHP 8.5. Creates coordination layer for complex component interactions with event dispatching, request/response handling, and colleague classes. Reduces coupling between interacting objects. Includes unit tests.
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/acc-create-mediator" ~/.claude/skills/majiayu000-claude-skill-registry-acc-create-mediator && rm -rf "$T"
manifest:
skills/data/acc-create-mediator/SKILL.mdsource content
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 | | Defines mediation contract |
| ConcreteMediator | | Implements coordination logic |
| ColleagueInterface | | Participant contract |
| AbstractColleague | | Base with mediator access |
| ConcreteColleagues | | Participating components |
| Tests | | 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:
- Full Mediator, Colleague, Command Bus, Event Mediator, Chat Room templatestemplates.md
- Real-world examplesexamples.md