This package has been deprecated in favour of php-kafka/php-avro-schema-generator
composer require nick-zh/php-avro-schema-generator "^0.1.0"
Since avro does not support external subschemas, this is just a small helper to unify your schemas and to create basic schemas from php classes (experimental!).
Schema template directories: directories containing avsc template files (with subschema) Output directory: output directory for the unified schema files
<?php
use NickZh\PhpAvroSchemaGenerator\Registry\SchemaRegistry;
use NickZh\PhpAvroSchemaGenerator\Merger\SchemaMerger;
$registry = (new SchemaRegistry())
->addSchemaTemplateDirectory('./schemaTemplates')
->load();
$merger = new SchemaMerger($registry, './schema');
$merger->merge();
./vendor/bin/avro-cli avro:subschema:merge ./example/schemaTemplates ./example/schema
Please note, that this feature is highly experimental.
You probably still need to adjust the generated templates, but it gives you a basic tempalte to work with.
Class direcotries: Directories containing the classes you want to generate schemas from
Output directory: output directory for your generated schema templates
<?php
use NickZh\PhpAvroSchemaGenerator\Registry\ClassRegistry;
use NickZh\PhpAvroSchemaGenerator\Generator\SchemaGenerator;
$registry = (new ClassRegistry())
->addClassDirectory('./example/classes')
->load();
$generator = new SchemaGenerator($registry, './example/schemaTemplates');
$schemas = $generator->generate();
$generator->exportSchemas($schemas);
./vendor/bin/avro-cli avro:schema:generate ./example/classes ./example/schemaTemplates