Skip to content

2.3.2

Choose a tag to compare

@ilvalerione ilvalerione released this 30 Sep 17:51
· 394 commits to 2.x since this release

Structured Output

Support for arrays with multiple object types.

You have two options to specify the PHP classes you want to build the array with:

Using the square brackets syntax:

class Person 
{
    ...
    
    /**
     * @var \App\TextBlock[]|\App\TableBlock[]
     */
    #[SchemaProperty(description: 'The list of tag for the user profile.', required: true)]
    #[ArrayOf([TextBlock::class, TableBlock::class])]
    public array $tags;
}

Or using the "array<...>" syntax:

class Person 
{
    ...
    
    /**
     * @var array<\App\TextBlock|\App\TableBlock>
     */
    #[SchemaProperty(description: 'The list of tag for the user profile.', required: true)]
    #[ArrayOf([TextBlock::class, TableBlock::class])]
    public array $tags;
}

As you can notice from the examples above you can pass an array of class-string to the ArrayOf validation rule to ensure the final array will contains only instances of the listed classes.

Documentation