Generates Chain of Responsibility pattern for PHP 8.4. Creates handler chains for request processing with middleware-style composition. Includes unit tests.
From accnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin accThis skill uses the workspace's default tool permissions.
references/examples.mdreferences/templates.mdCreates Chain of Responsibility pattern infrastructure for sequential request processing.
| Scenario | Example |
|---|---|
| Multiple processors | Validation, discounts, approvals |
| Unknown handlers | Plugin systems |
| Priority processing | First match wins |
| Middleware | HTTP pipeline, logging |
Path: src/Domain/{BoundedContext}/Handler/
{Name}HandlerInterface.php — Handler contract with setNext and handle methodsPath: src/Domain/{BoundedContext}/Handler/
Abstract{Name}Handler.php — Base class with chain linking logicPath: src/Domain/{BoundedContext}/Handler/
{Specific}{Name}Handler.php — Specific handler implementationsPath: src/Domain/{BoundedContext}/Handler/
{Name}ChainBuilder.php — Fluent builder for chain construction{Handler}Test.php — Individual handler tests{Name}ChainTest.php — Chain integration tests| Component | Path |
|---|---|
| Handler Interface | src/Domain/{BoundedContext}/Handler/ |
| Abstract Handler | src/Domain/{BoundedContext}/Handler/ |
| Concrete Handlers | src/Domain/{BoundedContext}/Handler/ |
| Chain Builder | src/Domain/{BoundedContext}/Handler/ |
| Pipeline | src/Application/Pipeline/ |
| Unit Tests | tests/Unit/Domain/{BoundedContext}/Handler/ |
| Component | Pattern | Example |
|---|---|---|
| Interface | {Name}HandlerInterface | ValidationHandlerInterface |
| Abstract | Abstract{Name}Handler | AbstractValidationHandler |
| Concrete | {Specific}{Name}Handler | EmailValidationHandler |
| Builder | {Name}ChainBuilder | ValidationChainBuilder |
| Test | {ClassName}Test | EmailValidationHandlerTest |
interface {Name}HandlerInterface
{
public function setNext(self $handler): self;
public function handle({RequestType} $request): {ResultType};
}
abstract class Abstract{Name}Handler implements {Name}HandlerInterface
{
private ?{Name}HandlerInterface $next = null;
public function setNext({Name}HandlerInterface $handler): {Name}HandlerInterface
{
$this->next = $handler;
return $handler;
}
public function handle({RequestType} $request): {ResultType}
{
if ($this->next !== null) {
return $this->next->handle($request);
}
return $this->getDefaultResult();
}
abstract protected function getDefaultResult(): {ResultType};
}
final class {Specific}Handler extends Abstract{Name}Handler
{
public function handle({RequestType} $request): {ResultType}
{
if ($this->canHandle($request)) {
return $this->process($request);
}
return parent::handle($request);
}
private function canHandle({RequestType} $request): bool
{
return {condition};
}
}
final class {Name}ChainBuilder
{
private array $handlers = [];
public function add({Name}HandlerInterface $handler): self
{
$this->handlers[] = $handler;
return $this;
}
public function build(): {Name}HandlerInterface
{
$first = $this->handlers[0];
$current = $first;
for ($i = 1; $i < count($this->handlers); $i++) {
$current = $current->setNext($this->handlers[$i]);
}
return $first;
}
}
$chain = (new ValidationChainBuilder())
->add(new NotEmptyValidationHandler('email'))
->add(new EmailValidationHandler('email'))
->add(new MinLengthValidationHandler('password', 8))
->build();
$result = $chain->validate($request);
if ($result->hasErrors()) {
throw new ValidationException($result->getMessage());
}
$vipHandler = new VipDiscountHandler();
$promoHandler = new PromoCodeDiscountHandler($promoCodes);
$bulkHandler = new BulkDiscountHandler();
$vipHandler->setNext($promoHandler);
$promoHandler->setNext($bulkHandler);
$result = $vipHandler->apply($discountRequest);
| Anti-pattern | Problem | Solution |
|---|---|---|
| Circular Chain | Infinite loop | Validate chain structure |
| No Default | Unhandled requests | Provide fallback handler |
| Coupled Handlers | Hard to reorder | Use interface properly |
| Missing Builder | Manual chain assembly | Create ChainBuilder |
| State in Handler | Non-reentrant | Make handlers stateless |
For complete PHP templates and examples, see:
references/templates.md — Handler Interface, Abstract Handler, Concrete Handler, Chain Builder, Pipeline templatesreferences/examples.md — Validation Chain, Discount Chain examples and testsProvides UI/UX resources: 50+ styles, color palettes, font pairings, guidelines, charts for web/mobile across React, Next.js, Vue, Svelte, Tailwind, React Native, Flutter. Aids planning, building, reviewing interfaces.