php-standard-library/type
Runtime type validation for PHP using “Parse, Don’t Validate”: coerce and assert unstructured input into well-typed data. Useful for APIs, configs, and user input with clear parsing rules, assertions, and predictable failures.
is_* checks (e.g., is_array(), is_callable()) by centralizing type logic, improving consistency and maintainability.Illuminate\Support\Facades\Validator) by offering low-level type utilities for custom validation rules or pre-processing.FormRequest classes or Validator extensions).is_fillable(), is_guarded()) suffices.symfony/polyfill, webmozart/assert).Arr::, Str::, Validator) already cover 80% of use cases, the package may not justify adoption.is_string() vs. is_stringable()).spatie/array-to-object, phpstan/phpstan) that could be extended instead?is_array()), or supplement them (e.g., for nullability checks)?Validator::extend())?null handling, recursive arrays) where this package outperforms Laravel’s defaults?Validator with type-specific rules (e.g., TypeRule::isNonEmptyArray()).$fillable, casts) is sufficient.app/Rules/TypeRule.php) to wrap package methods:
use PHPStandardLibrary\Type\Type;
use Illuminate\Contracts\Validation\Rule;
class TypeRule implements Rule {
public function passes($attribute, $value) {
return Type::isNonEmptyArray($value);
}
}
FormRequest or Validator::extend():
Validator::extend('non_empty_array', function ($attribute, $value, $parameters) {
return Type::isNonEmptyArray($value);
});
Type::isCallable($handler)).// Before
if (!is_callable($callback) || !is_array($config)) {
throw new InvalidArgumentException();
}
// After
Type::assertCallable($callback);
Type::assertNonEmptyArray($config);
phpunit/phpunit (for validation tests).laravel/framework (to ensure no namespace collisions).composer.json for exact version).symfony/polyfill (if used for type extensions).webmozart/assert (similar functionality).composer require php-standard-library/type).Type::isNonEmptyArray()).is_* calls reduce tech debt.null arrays) uniformly.Type::isCallable(null)) to avoid subtle bugs.Type::assertNonEmptyArray() for API inputs, not is_array()").Type::isStringable()).Type::is_* vs. native is_*).How can I help you explore Laravel packages today?