nick-zh/php-avro-schema-generator

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


README

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