event-engine/php-json-schema
Event Engine JSON Schema package for PHP. Generate/use JSON Schema with ImmutableRecord type detection. v1.x detects types via method return hints (PHP 7.2–7.3); v2.x uses PHP 7.4+ typed properties for improved schema support.
Validator facade, PSR-15 middleware, and FormRequest classes.Validator may still suffice).Nova/Forge integrations persist.Validator or symfony/validator with PHP 8.4 support in mind.FeatureTests remain necessary.Validator for JSON payloads in FormRequest classes, now fully compatible with PHP 8.4.Illuminate\Validation\ValidationException for consistent error handling.ValidateJsonSchema) with PHP 8.4 support:
public function handle($request, Closure $next) {
$validator = new \EventEngine\JsonSchema\Validator();
if (!$validator->validate($request->json()->all(), $this->schema)) {
throw new \Illuminate\Validation\ValidationException($validator->errors());
}
return $next($request);
}
public function handle(ExampleEvent $event) {
$validator = new \EventEngine\JsonSchema\Validator();
if (!$validator->validate($event->payload, $this->eventSchema)) {
Log::error('Invalid event payload', ['errors' => $validator->errors()]);
throw new \RuntimeException('Invalid event schema');
}
}
Validator.FormRequest classes for APIs.php artisan schema:validate).webonyx/graphql-php).config/schemas.php or YAML/JSON files (e.g., storage/schemas/).# storage/schemas/user_created.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": { "id": { "type": "string" } },
"required": ["id"]
}
// app/Services/JsonSchemaValidator.php
class JsonSchemaValidator {
public function validate(array $data, string $schemaPath): bool {
$validator = new \EventEngine\JsonSchema\Validator();
$schema = file_get_contents($schemaPath);
return $validator->validate($data, json_decode($schema, true));
}
}
Handler.php (unchanged).FeatureTests (unchanged):
public function test_json_schema_validation() {
$response = $this->postJson('/api/webhook', ['invalid' => true]);
$response->assertStatus(422);
}
v1/user.json).config/, storage/, or a database table (unchanged).array_is_list() or typed properties for schema metadata.dd() or dump() for schema validation debugging (no changes).symfony/validator, respect/validation) in high-throughput systems.Validator if critical issues arise.How can I help you explore Laravel packages today?