This package is abandoned and no longer maintained. The author suggests using the php-kafka/php-avro-schema-generator package instead.

PHP avro schema generator for subschema

v0.3.1 2020-09-02 12:47 UTC

This package is auto-updated.

Last update: 2020-11-16 13:14:44 UTC


This package has been deprecated in favour of php-kafka/php-avro-schema-generator

Avro schema generator for PHP

Actions Status Maintainability Test Coverage Latest Stable Version Latest Unstable Version


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!).

Merging subschemas / schemas

Schema template directories: directories containing avsc template files (with subschema) Output directory: output directory for the unified schema files

Merge subschemas (code)


use NickZh\PhpAvroSchemaGenerator\Registry\SchemaRegistry;
use NickZh\PhpAvroSchemaGenerator\Merger\SchemaMerger;

$registry = (new SchemaRegistry())

$merger = new SchemaMerger($registry, './schema');


Merge subschemas (command)

./vendor/bin/avro-cli avro:subschema:merge ./example/schemaTemplates ./example/schema

Generating schemas from classes

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

Generate schemas (code)


use NickZh\PhpAvroSchemaGenerator\Registry\ClassRegistry;
use NickZh\PhpAvroSchemaGenerator\Generator\SchemaGenerator;

$registry = (new ClassRegistry())

$generator = new SchemaGenerator($registry, './example/schemaTemplates');

$schemas = $generator->generate();


Merge subschemas (command)

./vendor/bin/avro-cli avro:schema:generate ./example/classes ./example/schemaTemplates