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

Type Laravel Package

php-standard-library/type

Runtime type validation for PHP built on the Parse, Don't Validate principle: coerce and assert unstructured input into well-typed data, with clear errors when values don't match.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit. The package positions itself as a boundary layer, not a framework component. Its value proposition — parse unstructured input once at the edge, then pass guaranteed-typed values inward — maps cleanly onto the places a Laravel application is structurally weakest: form request payloads, job/queue serialization, webhook ingestion, third-party API responses, and console/ETL jobs where data has already been marshalled and type guarantees are gone. That is a genuine architectural gap: Laravel's Validator validates user intent against rules, it does not produce typed domain values, and PHP's type system stops at the framework boundary. This package is the narrow band between "the request was acceptable" and "this object is safe to use."

The important caveat is that it sits orthogonally to Laravel's validation, not inside it. There is no service provider, no facade, no Validator::extend() hook out of the box. Any Laravel-native ergonomics — a ParsedRequest base class, custom rules, middleware — are work we own. That is a modest amount of glue code, but it must be scoped, owned, and documented, or it becomes yet another ad-hoc pattern rather than the standardization it's meant to deliver.

Integration feasibility. Technically low-friction: MIT licensed, Composer-installable, no native extensions, pure PHP, and usable as a set of static parsers/assertions. Wrapping it in a small internal package (acme/type-kit) that exposes Laravel-shaped helpers is the obvious play and keeps a seam for replacement. The realistic constraints are version-related: verify the PHP floor against your fleet (older Laravel 8/9 applications may be excluded), confirm the split package's version line is kept in lockstep with the monorepo, and confirm that assertion failures surface as exceptions you can map to Laravel's ValidationException / HTTP 422 rather than raw 500s.

Technical risk. The headline risk is not code quality — the package is a split of a long-running, actively maintained standard-library project — it is supply-chain and provenance opacity:

  • Misleading popularity signal. One star and zero dependents on the split repo tell you nothing useful; the real usage lives in the monorepo. The risk is not "nobody uses it," it is "you cannot see who uses it." Do not read the star count as a quality verdict in either direction; do read it as a signal that you will be the one doing the due diligence.
  • Release notes are pointers. The release manifests for 6.1.x through 6.3.0 all say "see the main repository release." That means changelog review, breaking-change detection, and CVE triage all happen in a repository you are not subscribed to. This is a small but real recurring operational tax and should be explicitly assigned.
  • Bus factor. Effectively a single-maintainer ecosystem project. Sustainability is a judgement call, not a technical one, and belongs in the decision record.
  • Metadata anomaly. The manifest shows a release dated 2026-10-28. Confirm whether that is a genuine forward-dated tag, a timezone/clock artifact, or generated metadata — a TPM should not sign off on a dependency whose release history they cannot explain.
  • Semantic risk. Coercion is the point of the package and also its sharpest edge. Coercive parsers can silently accept "0", "false", or [] where a stricter contract was intended. The team needs a written convention: coercion only at the outermost boundary, strict assertion everywhere inside.
  • Redundancy. Where PHP 8.1+ union types, constructor promotion, readonly properties, and PHPStan/Psalm at level 6+ already hold, the package adds little. Adopting it globally is over-engineering; adopting it at boundaries is defensible.

Key questions.

  1. Which specific incident classes are we targeting — null-in-array, string-for-int, missing keys in decoded JSON, malformed webhook payloads — and can we quantify them from the last two quarters of bug tickets and Sentry/APM events?
  2. What is the PHP version distribution across the fleet, and which applications are genuinely eligible?
  3. Is webmozart/assert already present anywhere? If so, what is the migration argument, or does this become a second assertion library in the codebase?
  4. Who owns the glue package, the upgrade cadence, and the upstream watch? Named individual, not a team name.
  5. What is the exit cost? Can the internal wrapper be reimplemented on top of native is_* checks and filter_var in under a sprint if the upstream project stalls?
  6. How does this interact with our static analysis baseline — does it replace, complement, or duplicate existing PHPStan rules?
  7. Does the DTO/parser pattern conflict with existing conventions ($casts, FormRequest, resource classes), and who arbitrates that?

Integration Approach

Stack fit. Strongest fit is a Laravel API/service layer where JSON crosses a trust boundary: FormRequest subclasses that parse into typed DTOs, queue job constructors that parse their own payloads, webhook controllers, and integration clients consuming third-party responses. Weaker fit is Eloquent hydration (casts already do this), Blade, and any code path where a static analyzer is already enforcing the contract. The honest framing for stakeholders: this is a boundary-hardening tool, not a codebase-wide typing initiative.

Migration path. Treat it as an additive, opt-in layer with a hard rule: no existing validation is removed until the replacement has a test proving equivalence.

  1. Freeze a seam. Create acme/type-kit — a thin internal package that depends on php-standard-library/type, exposes Laravel-idiomatic helpers (a ParsesRequests trait, a ValidatedPayload rule, a ParseException → ValidationException mapper), and re-exports nothing else. This is the single most important step: it caps the blast radius of the dependency at one package, and it caps the exit cost at one rewrite.
  2. Pilot one boundary. Pick the highest-value, lowest-blast-radius surface — typically a single high-traffic POST endpoint or a nightly batch job with known data-quality complaints. Success criteria agreed before the pilot: fewer 5xx responses, fewer type-related bug tickets, measurable reduction in defensive is_* lines.
  3. Codify conventions. Publish a short internal standard: coercion at the edge only, strict assertions inside, one error shape, parsers live in App\Data\..., every parser has a test for its failure message. This is the artifact that determines whether adoption feels like a standard or like a ninth opinion.
  4. Expand by pattern, not by directory. Convert one parser per PR, gated on the pilot's metrics. Resist a sweeping refactor.
  5. Review at the gate. After 60–90 days decide: promote, hold at pilot scope, or retire — with the retirement path being "reimplement acme/type-kit internals on native checks," which the seam makes cheap.

Compatibility. Verify and pin the PHP constraint against your lowest-supported runtime; confirm behavior on the Laravel versions actually in production (middleware pipeline order matters for where parsing runs); confirm no conflict with existing validation middleware, TrimStrings/ConvertEmptyStringsToNull, or API resource serialization; and confirm the package does not interfere with PHPStan/Psalm baselines or larastan inference — if it does, that friction is a hidden adoption cost worth surfacing early.

Sequencing. Dependency vetting and a fork/exit assessment → internal wrapper package → single pilot boundary with pre-agreed metrics → convention document → pattern-by-pattern expansion. Roughly one sprint of engineering plus one sprint of observation before any go/no-go. Do not sequence this ahead of or against a planned validation-standardization effort; run it as the runtime complement to that work, not as a competing initiative.

Operational Impact

Maintenance. Low code-churn, non-trivial attention-churn. Updates will be infrequent but will arrive bundled in monorepo releases that you must actively go read. Assign a named owner for: watching upstream releases, running the internal wrapper's test suite against new tags, and adjudicating the "should this be a parser or a FormRequest?" question. Budget it as a standing fraction of one engineer, not a project.

Support. Minimal vendor-style support; the practical support channel is the upstream issue tracker and your own documentation. The internal wrapper's README and the convention doc are the actual support artifacts — if they are thin, every new engineer will reinvent a parser and you will have defeated the purpose. Include a short "how to write a parser" guide with two or three real examples from the codebase.

Scaling. Runtime overhead per assertion is negligible; the scaling concern is aggregate volume in hot paths — per-item parsing inside large loops, or per-row parsing in ETL. Convention should be: parse the collection boundary once, not each element in a tight loop, and benchmark the first high-throughput job rather than assuming. Also watch memory on deeply nested structures and be deliberate about recursion limits for user-supplied arrays.

Failure modes. Enumerate them for on-call, because each produces a different incident signature:

  • Parser throws on valid-but-unexpected data (upstream API adds a field, or sends null where "" was expected). Mitigation: parsers must be versioned alongside the contract; alert on parse-failure rate per integration, not just on 5xx.
  • Over-coercion silently accepts bad data. The bad-data failure is the dangerous one because it is silent: it corrupts downstream state instead of failing fast. Mitigation: strict mode by default inside the application; coercion whitelisted at named boundaries.
  • Exception-to-HTTP mapping drift producing 500s where a 422 was intended. Mitigation: single ParseException handler in the wrapper, covered by a test.
  • Dependency unmaintained. Mitigation: the seam. The wrapper means the worst case is a contained rewrite, not a codebase-wide migration.
  • Version-skew across services — different apps on different majors of the monorepo. Mitigation: treat the wrapper as the version contract; services depend on the wrapper, not directly on the upstream package.

Ramp-up. Low technical learning curve, moderate convention learning curve. Engineers will understand the API in an hour; the thing that takes longer is internalizing where parsing belongs versus where FormRequest ends. Plan for a short internal walkthrough (60–90 minutes), a convention doc in the repo, and one exemplar PR that reviewers can point at. Onboarding impact should be net positive — replacing scattered is_* chains with named parsers reduces the time a new engineer spends reverse-engineering implicit type assumptions — but only if the naming is disciplined and the failure messages are good. Make failure-message quality an explicit review criterion.

Bottom line for the decision record. Recommend a scoped pilot, not a fleet-wide mandate. The package solves a real architectural gap at system boundaries, the integration cost is genuinely low, and the internal wrapper makes the exit cost low too. The reasons to proceed cautiously are provenance opacity and single-maintainer sustainability, not code quality — and both are fully mitigated by the wrapper seam plus a 90-day review gate with pre-agreed success metrics.

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.
muka/shape-reader
tdt/json
refinery29/php-cs-fixer-config
hotmeteor/eco-env
mvaliolahi/hydrate
wearede/tbcpay-php
parsnick/steak
thibaud-dauce/mattermost-php
multilinguals/apollo-client
antaresbr/collection
kr0lik/phpstan-rules
loco/loco
starfederation/datastar-php
yupmin/modern-phystrix
stephenjude/extended-artisan-commands
lumphp/laravel-macroable
lumphp/laravel-collections
lumphp/laravel-contracts
sermepa/sermepa
arkecosystem/fortify