API Schemas SchemaBuilder - evansims/openfga-php GitHub Wiki
Fluent builder for creating JSON schemas for data validation and transformation. This builder provides a fluent API for defining validation schemas for model classes, supporting various data types, formats, and validation constraints. It's used internally by the SDK to validate API responses and ensure data integrity.
Table of Contents
OpenFGA\Schemas
- SchemaBuilderInterface (interface)
public function array(
string $name,
array $items,
bool $required = false,
mixed $default = NULL,
): self
Add an array property to the schema.
Name | Type | Description |
---|---|---|
$name |
string |
The property name |
$items |
array |
|
$required |
bool |
Whether the property is required |
$default |
mixed |
Default value for optional properties |
self
— Returns the builder instance for method chaining
public function boolean(string $name, bool $required = false, mixed $default = NULL): self
Add a boolean property to the schema.
Name | Type | Description |
---|---|---|
$name |
string |
The property name |
$required |
bool |
Whether the property is required |
$default |
mixed |
Default value for optional properties |
self
— Returns the builder instance for method chaining
public function date(string $name, bool $required = false, mixed $default = NULL): self
Add a date property to the schema.
Name | Type | Description |
---|---|---|
$name |
string |
The property name |
$required |
bool |
Whether the property is required |
$default |
mixed |
Default value for optional properties |
self
— Returns the builder instance for method chaining
public function datetime(string $name, bool $required = false, mixed $default = NULL): self
Add a datetime property to the schema.
Name | Type | Description |
---|---|---|
$name |
string |
The property name |
$required |
bool |
Whether the property is required |
$default |
mixed |
Default value for optional properties |
self
— Returns the builder instance for method chaining
public function integer(string $name, bool $required = false, mixed $default = NULL): self
Add an integer property to the schema.
Name | Type | Description |
---|---|---|
$name |
string |
The property name |
$required |
bool |
Whether the property is required |
$default |
mixed |
Default value for optional properties |
self
— Returns the builder instance for method chaining
public function number(string $name, bool $required = false, mixed $default = NULL): self
Add a number (float) property to the schema.
Name | Type | Description |
---|---|---|
$name |
string |
The property name |
$required |
bool |
Whether the property is required |
$default |
mixed |
Default value for optional properties |
self
— Returns the builder instance for method chaining
public function object(string $name, string $className, bool $required = false): self
Add an object property to the schema.
Name | Type | Description |
---|---|---|
$name |
string |
The property name |
$className |
string |
The class name for the object property |
$required |
bool |
Whether the property is required |
self
— Returns the builder instance for method chaining
public function register(): OpenFGA\Schemas\Schema
Build and register the schema. Creates a Schema instance with all defined properties and registers it in the SchemaRegistry for use in validation.
Schema
— The built and registered schema
public function string(
string $name,
bool $required = false,
?string $format = NULL,
?array $enum = NULL,
mixed $default = NULL,
): self
Add a string property to the schema.
Name | Type | Description |
---|---|---|
$name |
string |
The property name |
$required |
bool |
Whether the property is required |
$format |
string | null
|
String format constraint (for example 'date', 'datetime') |
$enum |
array | null
|
Array of allowed string values |
$default |
mixed |
Default value for optional properties |
self
— Returns the builder instance for method chaining