typhoon/type
Typhoon Type provides an object abstraction over PHP’s modern type system for building tools that understand complex types. Define, print (stringify), and work with array shapes, object types, non-empty lists, and more in a consistent API.
Typhoon\Type schemas.nonEmptyStringT, intRangeT).Mapper in the example) to convert between JSON/XML and typed PHP objects, reducing runtime errors.Typhoon\Type definitions for IDE support (e.g., PHPStorm).if ($value instanceof nonEmptyStringT())) to replace is_string() + strlen() checks.Typhoon\Type checks.#[\Assert\Valid]) or strict typing—native tools may suffice.fromReflection()), which is intentionally removed from this package (see typhoon/algebra).*"Typhoon Type lets us catch bugs at runtime with minimal dev effort. Instead of writing verbose validation logic (e.g., if (!is_array($data) || !isset($data['people']))), we define types once—like arrayShapeT(['people' => nonEmptyListT(objectT(Person::class))])—and let the library enforce them. This reduces:
ROI: Faster development cycles for APIs, configs, and SDKs—with zero performance overhead (types are checked only when needed)."*
*"This is PHP’s answer to TypeScript’s runtime types. Key wins:
is_array() + array_key_exists() spaghetti with Typhoon\Type constraints.nonEmptyStringT or intRangeT(-5, 6) map directly to PHPDoc, so your IDE gets free type hints.Visitor pattern (e.g., add is() checks or serialization rules).Tradeoff: Some advanced features (e.g., reflection-based types) are in typhoon/algebra, but this package covers 90% of runtime needs with a clean API.
Proposal:
How can I help you explore Laravel packages today?