Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

PHP avro schema generator for subschema

License

Notifications You must be signed in to change notification settings

nick-zh/php-avro-schema-generator

Repository files navigation

Deprecation Notice

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

Installation

composer require nick-zh/php-avro-schema-generator "^0.1.0"

Description

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)

<?php

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

$registry = (new SchemaRegistry())
    ->addSchemaTemplateDirectory('./schemaTemplates')
    ->load();

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

$merger->merge();

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)

<?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);

Merge subschemas (command)

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