Search by

gilads-otiannoh254 / inertia-protocol

Framework-agnostic Inertia.js Wire Protocol Engine and Response Builder for PHP.

Maintainers

Package info

github.com/gilads-otiannoh24/inertia-protocol

pkg:composer/gilads-otiannoh254/inertia-protocol

Transparency log

Statistics

Installs: 17

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

v0.0.2 2026-09-04 19:30 UTC

This package is auto-updated.

Last update: 2026-09-05 13:02:07 UTC


README

A framework-agnostic, zero-dependency PHP 8.2+ library implementing the complete Inertia.js Wire Protocol specification.

Designed to power any PHP framework adapter (CodeIgniter 4, Symfony, Slim, RoadRunner, Swoole, Workerman, Laravel, or bespoke architectures) with 100% spec-compliant Inertia responses.

Features

  • 🚀 Zero Dependencies: Pure modern PHP 8.2+ with strict typing.
  • 📦 Complete Page Object Schema: Strict compliance with component, props (with always-present errors: {}), url, version, and conditional metadata.
  • 🔄 Advanced Prop Evaluation Model:
    • Inertia::always(...): Always resolved across full visits and partial reloads.
    • Inertia::lazy(...): Skipped on full visits, resolved only on partial reloads.
    • Inertia::defer(...): Grouped deferred props for follow-up loading with automatic rescue support.
    • Inertia::once(...): Evaluated once and cached client-side with optional expiration timestamps.
    • Inertia::merge(...), Inertia::prepend(...), Inertia::deepMerge(...): Client-side prop merging with matchPropsOn identification keys.
    • Inertia::scroll(...): Infinite scroll pagination cursor and metadata.
  • âš¡ Automated Protocol Handlers:
    • Asset Versioning: Automatically returns 409 Conflict with X-Inertia-Location and X-Inertia-Version on GET mismatches.
    • External Visits: Inertia::location($url) generates 409 Conflict with X-Inertia-Location.
    • Fragment Redirects: Inertia::redirectWithFragment($url) generates 409 Conflict with X-Inertia-Redirect.
    • Precognition: Returns 204 No Content with Precognition: true and Vary: Precognition.
    • Partial Reload Filtering: Respects X-Inertia-Partial-Data, X-Inertia-Partial-Except, X-Inertia-Reset, and X-Inertia-Except-Once-Props.

Installation

composer require gilads-otiannoh254/inertia-protocol

Usage

1. Basic Response Evaluation

use Inertia\Protocol\Inertia;
use Inertia\Protocol\Support\NativeRequest;

// 1. Build an Inertia response
$response = Inertia::render('Users/Index', [
    'users' => fn() => UserModel::paginate(),
    'siteName' => Inertia::always('My App'),
    'analytics' => Inertia::defer(fn() => Analytics::get(), group: 'analytics'),
]);

// 2. Evaluate against incoming request
$decision = $response->toDecision(NativeRequest::fromGlobals());

if ($decision->isJson()) {
    // Send HTTP JSON response (status: 200, headers: decision->headers, body: decision->content)
    http_response_code($decision->statusCode);
    foreach ($decision->headers as $name => $value) {
        header("{$name}: {$value}");
    }
    echo json_encode($decision->content);
} else {
    // Render full HTML root template with embedded page object
    echo view('app', ['page' => $decision->pageObject->toArray()]);
}

2. External & Fragment Redirects

// External URL visit
$decision = Inertia::location('https://external-payment.com/checkout');

// URL Fragment Redirect
$decision = Inertia::redirectWithFragment('https://my-app.com/posts#comment-42');

3. Precognition Validation

$decision = Inertia::precognitionSuccess();
// Emits 204 No Content with Precognition-Success headers

License

MIT License. See LICENSE for details.