Skip to content
acc-create-chain-of-responsibility logo

Chain of Responsibility Pattern Generator

acc-create-chain-of-responsibility

Generates Chain of Responsibility pattern for PHP 8.5. Creates handler chains for request processing with middleware-style composition. Includes unit tests.

SKILL.md

Full skill instructions

Chain of Responsibility Pattern Generator

Creates Chain of Responsibility pattern infrastructure for sequential request processing.

When to Use

ScenarioExample
Multiple processorsValidation, discounts, approvals
Unknown handlersPlugin systems
Priority processingFirst match wins
MiddlewareHTTP pipeline, logging

Component Characteristics

HandlerInterface

  • Defines handle method
  • Optional setNext for linking
  • Returns result or delegates

AbstractHandler

  • Implements chain linking
  • Provides base handle logic
  • Simplifies concrete handlers

Concrete Handlers

  • Process specific requests
  • Decide to handle or pass
  • Can terminate or continue chain

Generation Process

Step 1: Generate Handler Interface

Path: src/​Domain/​{BoundedContext}/​Handler/

  1. {Name}HandlerInterface.php — Handler contract with setNext and handle methods

Step 2: Generate Abstract Handler

Path: src/​Domain/​{BoundedContext}/​Handler/

  1. Abstract{Name}Handler.php — Base class with chain linking logic

Step 3: Generate Concrete Handlers

Path: src/​Domain/​{BoundedContext}/​Handler/

  1. {Specific}{Name}Handler.php — Specific handler implementations

Step 4: Generate Chain Builder (Optional)

Path: src/​Domain/​{BoundedContext}/​Handler/

  1. {Name}ChainBuilder.php — Fluent builder for chain construction

Step 5: Generate Tests

  1. {Handler}Test.php — Individual handler tests
  2. {Name}ChainTest.php — Chain integration tests

File Placement

ComponentPath
Handler Interfacesrc/​Domain/​{BoundedContext}/​Handler/
Abstract Handlersrc/​Domain/​{BoundedContext}/​Handler/
Concrete Handlerssrc/​Domain/​{BoundedContext}/​Handler/
Chain Buildersrc/​Domain/​{BoundedContext}/​Handler/
Pipelinesrc/​Application/​Pipeline/
Unit Teststests/​Unit/​Domain/​{BoundedContext}/​Handler/

Naming Conventions

ComponentPatternExample
Interface{Name}HandlerInterfaceValidationHandlerInterface
AbstractAbstract{Name}HandlerAbstractValidationHandler
Concrete{Specific}{Name}HandlerEmailValidationHandler
Builder{Name}ChainBuilderValidationChainBuilder
Test{ClassName}TestEmailValidationHandlerTest

Quick Template Reference

Handler Interface

interface {Name}HandlerInterface
{
    public function setNext(self $handler): self;
    public function handle({RequestType} $request): {ResultType};
}

Abstract Handler

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};
}

Concrete Handler

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};
    }
}

Chain Builder

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;
    }
}

Usage Examples

Validation Chain

$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());
}

Discount Chain

$vipHandler = new VipDiscountHandler();
$promoHandler = new PromoCodeDiscountHandler($promoCodes);
$bulkHandler = new BulkDiscountHandler();

$vipHandler->setNext($promoHandler);
$promoHandler->setNext($bulkHandler);

$result = $vipHandler->apply($discountRequest);

Anti-patterns to Avoid

Anti-patternProblemSolution
Circular ChainInfinite loopValidate chain structure
No DefaultUnhandled requestsProvide fallback handler
Coupled HandlersHard to reorderUse interface properly
Missing BuilderManual chain assemblyCreate ChainBuilder
State in HandlerNon-reentrantMake handlers stateless

References

For complete PHP templates and examples, see:

  • references/​templates.md — Handler Interface, Abstract Handler, Concrete Handler, Chain Builder, Pipeline templates
  • references/​examples.md — Validation Chain, Discount Chain examples and tests

More DevOps & CI/CD skills

Project scaffolding, deployment configuration, and CI/CD setup for Google ADK agents.

6K 472.6K
View

Set up tracing, logging, and monitoring for deployed ADK agents across Cloud Trace, BigQuery, and third-party platforms.

6K 472.6K
View

Enterprise Azure infrastructure architect generating Bicep or Terraform from workload descriptions.

1.5K 454.3K
View
azure-kubernetes logo
DevOps & CI/CD

azure-kubernetes

Plan and configure production-ready Azure Kubernetes Service clusters with Day-0 and Day-1 best practices.

1.5K 447.1K
View

Raw mechanical interfaces fusing Swiss typographic print with military terminal aesthetics. Rigid grids, extreme type scale contrast, utilitarian color, analog degradation effects. For data-heavy dashboards, portfolios, or editorial sites that need to feel like declassified blueprints.

92.7K 354.9K
View
just-scrape logo
DevOps & CI/CD

just-scrape

Web search, scraping, extraction, crawling, and monitoring via ScrapeGraph AI CLI.

69 245K
View

Skill for working with Firebase Hosting (Classic). Use this when you want to deploy static web apps, Single Page Apps (SPAs), or simple microservices. Do NOT use for Firebase App Hosting.

462 159.7K
View

Deploy and manage web apps with Firebase App Hosting. Use this skill when deploying Next.js/Angular apps with backends.

462 159.1K
View
deploy-to-vercel logo
DevOps & CI/CD

deploy-to-vercel

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

31.9K 146.6K
View
programmatic-seo logo
DevOps & CI/CD

programmatic-seo

Build SEO-optimized pages at scale using templates, data, and proven playbook patterns.

53.3K 140.1K
View

Design and build isolated, reusable Convex backend components with clear boundaries and app-facing wrappers.

63 123.5K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
Imagica logo
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View