From acc
Generates Chain of Responsibility pattern for PHP 8.4, creating handler chains for middleware-style request processing like validation and approvals. Includes unit tests.
How this skill is triggered — by the user, by Claude, or both
Slash command
/acc:create-chain-of-responsibilityThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Creates Chain of Responsibility pattern infrastructure for sequential request processing.
Creates 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 testsnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin accImplements Chain of Responsibility pattern to decouple request senders from handlers, passing requests along a chain until handled.
Generates Decorator pattern for PHP 8.4: interface, abstract decorator, concrete decorators (logging, caching, metrics, transactional), optional factory, and unit tests. For dynamic behavior without inheritance.
Implements the Chain of Responsibility pattern with linked handler chains and async middleware pipelines. Useful for request routing, validation, and event processing.