simplesamlphp/assert
A fork of webmozart/assert that lets every assertion throw a custom exception via an extra parameter, falling back to AssertionFailedException. It also adds XML/SAML2-specific assertions for SimpleSAMLphp projects.
validURI, validURL, validURN, validNCName, validQName, validDuration, validNMToken(s), validHexBinary, stringPlausibleBase64, validDateTime. If our roadmap includes SAML2, XML signature/canonicalization, or any protocol where schema datatypes must be enforced, this is a legitimate “buy/borrow” rather than hand-rolling regexes we’d get wrong.Throwable per assertion, falling back to an AssertionFailedException (an UnexpectedValueException, not InvalidArgumentException) — supports cleaner error contracts: mapped API status codes, typed exceptions for retry/fallback logic, and less exception-string matching in observability. This is a decision about how failures are surfaced, which affects support cost and incident triage.Assert::extend, and Assert::custom are features of this package. The README does not document them; the documented additions are the XML/SAML datatype checks above plus a custom-exception mechanism. Any roadmap item premised on “this package gives us PHP 8.1 enum validation” is built on a false premise and should not drive adoption.composer.json files.Adopt (narrowly) if:
xs:NCName, xs:QName, xs:duration, xs:hexBinary, and base64/URI checks are real requirements.webmozart/assert yourself.Look elsewhere if:
enum types and backed-enum casting, or plain webmozart/assert / Symfony Validator. Do not select this package for that.webmozart/assert, so adopting it means being deliberate about which assertion library owns a given call site, and it shouldn’t sit alongside it by accident.Practical caveat for the team: the package is small enough that “vendor the six assertions we use” is a credible alternative and removes the licensing, bus-factor, and dependency-conflict risks entirely. That option should be on the table for any decision review.
Executive summary: This is a small, low-risk-per-line, low-strategic-value utility library. It does one thing well — it lets you assert a value and choose exactly which exception is thrown when the assertion fails — and adds a set of strict XML/SAML datatype checks. It is relevant to us only if we build SAML2 or XML protocol integrations. It is not a validation framework, not a Laravel component, and not a modernization play; recommending it broadly would add licensing review and maintenance exposure for little gain. Recommendation: no org-wide adoption; evaluate as a contained dependency in the SAML/XML workstream, or reproduce the handful of XML assertions internally.
For engineering: The API is a static facade over webmozart/assert with an extra trailing ?Throwable $exception parameter per assertion; on failure it throws the supplied throwable, otherwise a custom AssertionFailedException extending UnexpectedValueException. Use it for invariant/contract checks at boundaries (constructors, adapters, config hydration, XML builders), where throwing a specific domain exception is genuinely useful. Do not use it for user input validation, do not use it in hot loops, and do not assume enum or extend/custom helpers exist — verify against the installed version before designing around them. Pin the version, note the LGPL-2.1 obligation, and add a short ADR recording why the dependency exists so it doesn’t silently spread to unrelated services.
How can I help you explore Laravel packages today?