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


Namespace

OpenFGA\Schemas


Source

View source code


Related Classes


Methods

array

public function array(
    string $name,
    array $items,
    bool $required = false,
    mixed $default = NULL,
): self

Add an array property to the schema.

View source


Parameters

Name Type Description
$name string The property name
$items array
$required bool Whether the property is required
$default mixed Default value for optional properties

Returns

self — Returns the builder instance for method chaining


boolean

public function boolean(string $name, bool $required = false, mixed|null $default = NULL): self

Add a boolean property to the schema.

View source


Parameters

Name Type Description
$name string The property name
$required bool Whether the property is required
$default mixed | null Default value for optional properties

Returns

self — Returns the builder instance for method chaining


date

public function date(string $name, bool $required = false, mixed|null $default = NULL): self

Add a date property to the schema.

View source


Parameters

Name Type Description
$name string The property name
$required bool Whether the property is required
$default mixed | null Default value for optional properties

Returns

self — Returns the builder instance for method chaining


datetime

public function datetime(string $name, bool $required = false, mixed|null $default = NULL): self

Add a datetime property to the schema.

View source


Parameters

Name Type Description
$name string The property name
$required bool Whether the property is required
$default mixed | null Default value for optional properties

Returns

self — Returns the builder instance for method chaining


integer

public function integer(string $name, bool $required = false, mixed|null $default = NULL): self

Add an integer property to the schema.

View source


Parameters

Name Type Description
$name string The property name
$required bool Whether the property is required
$default mixed | null Default value for optional properties

Returns

self — Returns the builder instance for method chaining


number

public function number(string $name, bool $required = false, mixed|null $default = NULL): self

Add a number (float) property to the schema.

View source


Parameters

Name Type Description
$name string The property name
$required bool Whether the property is required
$default mixed | null Default value for optional properties

Returns

self — Returns the builder instance for method chaining


object

public function object(string $name, string $className, bool $required = false): self

Add an object property to the schema.

View source


Parameters

Name Type Description
$name string The property name
$className string The class name for the object property
$required bool Whether the property is required

Returns

self — Returns the builder instance for method chaining


register

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.

View source


Returns

Schema — The built and registered schema


string

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.

View source


Parameters

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&lt;string&gt; | null Array of allowed string values
$default mixed Default value for optional properties

Returns

self — Returns the builder instance for method chaining

⚠️ **GitHub.com Fallback** ⚠️