API Schemas SchemaBuilderInterface - evansims/openfga-php GitHub Wiki
Interface for building schema definitions using the builder pattern. This interface provides a fluent API for constructing schema definitions that describe the structure and validation rules for OpenFGA model objects. The builder pattern allows for easy, readable schema creation with method chaining. Schema builders support all common data types including strings, integers, booleans, dates, arrays, and complex objects. Each property can be configured with validation rules such as required status, default values, format constraints, and enumeration restrictions. Example usage: php $schema = $builder ->string('name', required: true) ->integer('age', required: false, default: 0) ->object('address', Address::class, required: true) ->register();
The built schemas are automatically registered in the SchemaRegistry for use during validation and object transformation throughout the OpenFGA system.
Table of Contents
OpenFGA\Schemas
- SchemaBuilder (implementation)
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|null $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 | null
|
Default value for optional properties |
self
— Returns the builder instance for method chaining
public function date(string $name, bool $required = false, mixed|null $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 | null
|
Default value for optional properties |
self
— Returns the builder instance for method chaining
public function datetime(string $name, bool $required = false, mixed|null $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 | null
|
Default value for optional properties |
self
— Returns the builder instance for method chaining
public function integer(string $name, bool $required = false, mixed|null $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 | null
|
Default value for optional properties |
self
— Returns the builder instance for method chaining
public function number(string $name, bool $required = false, mixed|null $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 | null
|
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(): 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|null $format = NULL,
array<string>|null $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< string> | null
|
Array of allowed string values |
$default |
mixed |
Default value for optional properties |
self
— Returns the builder instance for method chaining