API Schemas ValidationServiceInterface - evansims/openfga-php GitHub Wiki
Service for validating data against schemas. This service encapsulates the validation logic, separating it from object construction concerns. It validates data structures against registered schemas and provides detailed error reporting.
Table of Contents
OpenFGA\Schemas
- ValidationService (implementation)
public function hasSchema(string $className): bool
Check if a schema is registered for a class.
Name | Type | Description |
---|---|---|
$className |
string |
The class name to check |
bool
— True if schema is registered
public function registerSchema(SchemaInterface $schema): self
Register a schema for validation.
Name | Type | Description |
---|---|---|
$schema |
SchemaInterface |
The schema to register |
self
— For method chaining
public function validate(mixed $data, string $className): array<string, mixed>
Validate data against a schema. Validates the provided data against the schema for the specified class. This method only validates structure and types, it does not construct objects.
Name | Type | Description |
---|---|---|
$data |
mixed |
The data to validate |
$className |
string |
The class name whose schema to validate against |
array<
string,
mixed>
— The validated data (may be normalized/cleaned)
public function validateProperty(mixed $value, SchemaPropertyInterface $property, string $path): mixed
Validate a property value against its schema definition.
Name | Type | Description |
---|---|---|
$value |
mixed |
The value to validate |
$property |
SchemaPropertyInterface |
The property schema |
$path |
string |
The property path for error reporting |
mixed
— The validated value