Backend Overview
handlr-backend (phillipsharring/handlr-backend, namespace Handlr\) is a lightweight, middleware-style PHP framework built around the Pipe + Handler pattern. It separates HTTP concerns from business logic, and makes object-level authorization structural rather than something you remember to check.
The design bias is explicit over magic: constructor injection everywhere, no static global state, small interfaces you can read top to bottom. It is not a framework pretending to be Laravel — there are no facades and nothing resolves out of a hidden global.
The core abstractions
- Pipe — onion middleware that sees
Request/Response. Auth, validation, CORS, CSRF, resolution. Short-circuits by returning aResponseinstead of calling$next. - Handler — pure business logic. Receives a typed
HandlerInput, returns aHandlerResult. No HTTP awareness — the same handler serves an HTTP request and an event dispatch. - HandlerInput — a validated, sanitized input object. Identical whether the input came from an HTTP request or an event.
- HandlerResult — a structured outcome:
$this->result->ok($data)or$this->result->fail($errors). A value, never a thrown string.
Below the pipe layer, everything is Handler/HandlerInput.
The request path
Kernel → Router::dispatch() → request-scoped Container → Pipeline of Pipes → HandlerTwo ideas hold it together:
- Laziness — route pipes and the handler are deferred, constructed only when the chain reaches them. An auth or policy short-circuit means the handler never exists.
- Scope binding — each request gets a throwaway child container. A pipe can bind a value into it (a resolved record); a downstream handler receives that value by type hint. No request bag, no string keys.
Read Core Concepts for the full flow.
Where to go next
| Page | What it covers |
|---|---|
| Core Concepts | Pipe / Handler / Input / Result, the lifecycle, laziness |
| Container | DI and the request scope |
| Routing & Junctions | routes, groups, junctions, resolve/policy binding |
| Authorization | resolve → consult → bind: policies, resolution, invariants |
| Validation | the rule/sanitizer engine |
| Database | Table, Record, Db, Query, migrations |
| API Responses | the JSON envelope (Presenter) |
| Auth | session auth + coarse permissions |
| Events & Listeners | the synchronous event bus |
| Service Providers | how features register themselves |
| CLI & Makers | composer run make:*, migrate, seed |
Install
composer require phillipsharring/handlr-backendOr scaffold a full app (backend + frontend) with composer create-project phillipsharring/handlr-app my-project — see Installation.
