php-collective/dto
php-collective/dto is a lightweight PHP package for defining typed data transfer objects. Hydrate DTOs from arrays or Laravel requests, cast nested DTOs and collections, validate data, and keep application boundaries clean with simple, expressive classes.
fromArray() / fromJson() + toArray() / toJson() gives a single, testable seam — useful for scoping "how much work is the Stripe webhook integration?" questions.TransformerRegistry (casters for hydration, serializers for output) plus per-field transformFrom / transformTo hooks means there is now a real decision about where custom type mapping lives: global registry, per-field transform, or a hand-written mapper outside the package. Worth pinning down before teams diverge.strictTypes; unsafe callables fall back to the runtime path). This is a performance lever we can turn on for hot payloads and leave off elsewhere — not an all-or-nothing commitment.fromArray(), and scoped guards so casters affect input only and serializers affect output only. That is the classic codegen risk — generated and interpreted paths diverging. Any adoption decision should explicitly budget for parity testing between generated and non-generated paths.Adopt when most of these hold:
strictTypes declared for compiled field transforms). If throughput is not a constraint, ignore the codegen entirely; nothing else depends on it.transformFrom / transformTo covers the "this one field needs custom handling" case without a global caster, and the 0.1.20 change makes that cheap without changing semantics.from() on an existing object or array means you can introduce DTOs incrementally at one boundary rather than converting the whole codebase.Look elsewhere when:
spatie/laravel-data or Laravel API Resources cover that ground with far more community support.To executives: This is a small, MIT-licensed utility that makes the data moving between our systems explicitly typed instead of loose arrays. The business value is defect prevention: a large share of integration bugs are shape mismatches — a field renamed on one side, a string where a number was expected, a null where an object was assumed. Typed DTOs move those failures from production to development. The latest release is maintenance-grade: a correctness fix in the generated mapping path and a performance improvement for custom field transforms. Cost is low and reversible; the main caveat is unchanged — it is an early-stage community project, so we pin the version and treat it as a replaceable internal detail rather than a strategic dependency.
To engineering: Adopt it at one boundary first — a webhook handler or a public API response. It gives you typed construction and serialization with nested DTOs and typed collections, enums, dates, per-field transforms, and a global caster/serializer registry, without the implicit magic of larger frameworks. There is no heavy framework lock-in: the DTOs are plain PHP classes, and the compiled fast path is an opt-in performance feature rather than a requirement. The 0.1.20 fix is a reminder that generated code can drift from the runtime path — treat that as a testing obligation, not a reason to avoid the feature. Recommend four guardrails: pin the version; wrap fromArray/toArray behind our own small base class or trait so the dependency is swappable; require a round-trip test per DTO; and require that any DTO using the generated path is also exercised through the non-generated path in CI.
To the architecture/security reviewer: Flag the dependency-health score honestly — 30 stars, unknown repository provenance, single maintainer. The 0.1.20 release is a net positive signal (issues triaged and fixed, perf work landed) but also confirms the package now contains a code-generation layer, which is more to audit than plain mapping helpers. Mitigation is containment: no DTO on an authentication, payment, or PII-handling critical path until we have either contributed upstream or vendored the code, and no codegen on those paths regardless.
How can I help you explore Laravel packages today?