Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Chain Bundle Laravel Package

mike4git/chain-bundle

mike4git/chain-bundle is a lightweight PHP package for building chain-of-responsibility pipelines. It lets you compose handlers into reusable sequential workflows, pass requests through each step, and keep processing logic clean, modular, and easy to extend in framework-based applications.

View on GitHub
Deep Wiki
Context7

Getting Started

chain-bundle is a small utility for composing handlers into a single, ordered chain (a lightweight chain-of-responsibility). Version 1.0.0 is the initial release, and the release notes are a single sentence — so budget 20 minutes to read the source before wiring it into anything important.

Minimal steps:

composer require <vendor>/chain-bundle

Then, in order:

  1. Read the interfaces first. Look in src/ for the handler contract (typically handle()), the chain/runner class, and any ChainBundleServiceProvider. The contract's return type is the single most important detail — it determines whether a handler passes a value along, mutates it, or short-circuits.
  2. Check for a facade or container binding. If the provider registers a singleton chain, you can resolve it rather than new-ing it, which is what makes handler constructor injection work.
  3. Inspect composer.json for the illuminate/* constraints — v1.0.0 packages often pin loosely and can drift on Laravel majors.

First use case: a sequential processing pipeline where each step either enriches a payload or stops the chain — for example, validating and normalising an inbound webhook before dispatching jobs, or a multi-step order-import (parse → validate → dedupe → persist). Start with two or three handlers and a test, not a twelve-stage pipeline.

Implementation Patterns

Register handlers as a list, not a discovery mechanism. The idiomatic shape is a service provider (often a domain-specific one, not AppServiceProvider) that pushes handlers onto the chain in explicit order:

$this->app->make(OrderChain::class)
    ->push(ParsePayload::class)
    ->push(ValidateOrder::class)
    ->push(DeduplicateOrder::class);

Explicit ordering in one place is far easier to reason about than annotation- or convention-based discovery.

Resolve handlers from the container. Handlers that are new-ed directly can't take dependencies. Keep handler constructors lean (a repository, a logger, maybe a config value) and let the container build them.

Treat the payload as immutable where you can. Returning a new DTO from each handler makes the chain trivially testable and prevents a downstream handler from silently mutating state an upstream one relied on. If the package's contract is by-reference, document that convention in the chain class's docblock.

Compare against Illuminate\Pipeline\Pipeline before committing. Laravel already ships a pipeline with via()/through()/then(). Reach for chain-bundle when you want a named, reusable, DI-resolved chain that multiple call sites invoke identically — not when you need a one-off pass over middleware. If your chain lives inside a single controller method, the framework pipeline is the lower-overhead choice.

Test the chain, and test each handler alone. A chain-level test asserts ordering and short-circuit behaviour; per-handler tests assert the transformation. A fake/stub chain is useful when a feature test only cares that the chain was invoked, not what it did.

Compose chains for larger flows. If the package supports nesting a chain as a handler, use it to build small named sub-flows (e.g. PaymentChain inside CheckoutChain) rather than one flat 15-step list.

Gotchas and Tips

  • Short-circuit semantics are the #1 source of bugs. Confirm precisely what a handler returns to stop the chain (null? false? a specific result object?) versus to continue. Write one test that pins this down and keep it forever.
  • Handle exceptions deliberately. Decide whether a thrown exception aborts the whole chain or is caught and turned into a stop result. Without a decision, the package default will surprise you later; a thin wrapper that normalises exceptions to results is usually worth it.
  • Watch for handler state leakage. If handlers are registered as singletons and hold per-request state (accumulators, counters), a long-running queue worker or Octane process will bleed state between requests. Prefer transient bindings for anything stateful.
  • Ordering lives in code, so it can silently drift. Guard it with one assertion test on the resolved handler list; it catches accidental reordering during refactors.
  • Debugging a chain: add a temporary no-op handler that logs the payload and the handler class name, or wrap each handler in a try/catch that logs with context. A broken chain is otherwise a stack trace with no indication of which step failed.
  • No documented config surface at v1.0.0. If a config/chain-bundle.php is published, diff it against the package's own defaults on upgrade — early releases frequently rename keys within the first few minors.
  • Pin the version. ^1.0 is reasonable, but for a 1.0.0 with a one-line changelog, read the source at the exact tag you install and note the tag in your PR description. Expect the API to settle over the next few releases.
  • Extension point to keep in mind: if the chain exposes a resolver or a per-handler wrapper hook, that is the clean place for cross-cutting concerns (timing, logging, transaction boundaries) — preferable to a base AbstractHandler class that every handler inherits from.
  • Keep handlers single-purpose. The pattern's value collapses into a glorified service method if handlers grow branching logic; each handler should read as a sentence.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
cgv/localized-resource