PHP code example of cognesy / instructor-schema

1. Go to this page and download the library: Download cognesy/instructor-schema library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cognesy / instructor-schema example snippets



use Cognesy\Schema\SchemaFactory;

$factory = SchemaFactory::default();

$schema = $factory->schema(User::class);
$jsonSchema = $factory->toJsonSchema($schema);


use Cognesy\Schema\SchemaBuilder;

$schema = SchemaBuilder::define('user')
    ->string('name', 'User name')
    ->int('age', 


use Cognesy\Schema\SchemaFactory;
use Symfony\Component\TypeInfo\Type;

$factory = SchemaFactory::default();

$nickname = $factory->propertySchema(
    type: Type::string(),
    name: 'nickname',
    description: 'Optional nickname',
    nullable: true,
    hasDefaultValue: true,
    defaultValue: null,
);


use Cognesy\Schema\JsonSchemaParser;

$parser = new JsonSchemaParser();
$objectSchema = $parser->fromJsonSchema($jsonSchemaArray);