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


Namespace

OpenFGA\Schemas


Source

View source code


Implements


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 $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 Default value for optional properties

Returns

self — Returns the builder instance for method chaining


date

public function date(string $name, bool $required = false, mixed $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 Default value for optional properties

Returns

self — Returns the builder instance for method chaining


datetime

public function datetime(string $name, bool $required = false, mixed $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 Default value for optional properties

Returns

self — Returns the builder instance for method chaining


integer

public function integer(string $name, bool $required = false, mixed $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 Default value for optional properties

Returns

self — Returns the builder instance for method chaining


number

public function number(string $name, bool $required = false, mixed $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 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(): 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.

View source


Returns

Schema — The built and registered schema


string

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.

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 | 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** ⚠️