Guard routes, queues, and pipelines by applying ternary logic before requests reach your core domain.
| Middleware | Description | Namespace |
|---|---|---|
TernaryGateMiddleware |
Evaluates multiple attributes (user/request) using a configurable ternary operator | Trilean\Http\Middleware |
RequireTernaryTrue |
Blocks the request unless the specified attribute resolves to TRUE |
Trilean\Http\Middleware |
- Register in
Kernelprotected $routeMiddleware = [ 'ternary.gate' => \Trilean\Http\Middleware\TernaryGateMiddleware::class, 'ternary.requireTrue' => \Trilean\Http\Middleware\RequireTernaryTrue::class, ];
- Attach to Routes
Route::middleware('ternary.requireTrue:kyc_state')->group(function () { // protected routes });
- Default parameters:
keys,source,operator,weights,requiredRatio,responseFactory. - Flow:
- Collect values from request or authenticated user.
- Normalize via
ternary(). - Apply operator (
and,or,xor,consensus,weighted). - Produce
TernaryDecisionReportwith explanations. - Block with structured JSON (423/403) when result is
FALSE.
- Advanced use:
Expects
Route::middleware('ternary.gate:checks,request,weighted,requiredRatio=0.66') ->post('/payouts', PayoutController::class);
checkspayload (array/string of states). - Custom response: Supply a
responseFactoryclosure receiving(Request $request, TernaryDecisionReport $report).
- Simple usage:
Route::middleware('ternary.requireTrue:user.compliance_state') ->post('/investments', ...);
- Sources:
user,request,route,payload(defaultuser). - Behavior: Aborts with
403orRetry-Afterif state isFALSEorUNKNOWN(configurable).
- Both middleware log via
TrileanLoggerwhen enabled (config('trilean.logging')). TernaryGateMiddlewarecan fireTernaryDecisionEvaluatedevents for downstream integrations.- Export to Prometheus/DataDog with
DecisionMetrics::record($report).
- Use
actingAswith users returningTernaryStateattributes. - For payload checks, call
$this->postJson('/endpoint', ['checks' => ['true', 'unknown']]). - Assert JSON fragments when reports are included in the response.
- Compliance: Block financial operations until audits stop being
UNKNOWN. - Feature Early Access: Gate routes behind centralized flags resolved via ternary consensus.
- Infrastructure: Prevent deploy endpoints from running while CI signals
FALSE.
Middleware enforce business logic at the edge, ensuring inconsistent states are handled before they reach critical code paths.