Download the PHP package php-kafka/php-avro-schema-generator without Composer
On this page you can find all versions of the php package php-kafka/php-avro-schema-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-avro-schema-generator
Avro schema generator for PHP
Installation
Description
This library enables you to:
- Manage your embedded schema as separate files
- The library is able to merge those files
- The library is able to generate avsc schema templates from PHP classes
Merging subschemas / schemas
Schema template directories: directories containing avsc template files (with subschema)
Output directory: output directory for the merged schema files
Console example
PHP example
Merge optimizers
There are optimizers that you can enable for merging schema:
- FullNameOptimizer: removes unneeded namespaces
- FieldOrderOptimizer: the first fields of a record schema will be: type, name, namespace (if present)
- PrimitiveSchemaOptimizer: Optimizes primitive schema e.g.
{"type": "string"}
to"string"
How to enable optimizer:
Console example
PHP Example
Generating schemas from classes
You will need to adjust the generated templates, but it gives you a good starting point to work with.
Class directories: Directories containing the classes you want to generate schemas from
Output directory: output directory for your generated schema templates
After you have reviewed and adjusted your templates you will need to merge them (see above)
Console example
PHP Example
The generator is able to detect types from:
- doc comments
- property types
- doc annotations
- @avro-type to set a fixed type instead of calculating one
- @avro-default set a default for this property in your schema
- @avro-doc to set schema doc comment
- @avro-logical-type set logical type for your property (decimal is not yet supported, since it has additional parameters)
Disclaimer
In v1.3.0
the option --optimizeSubSchemaNamespaces
was added. It was not working fully
in the 1.x
version and we had some discussions (#13) about it.
Ultimately the decision was to adapt this behaviour fully in v2.0.0
so you might want to
upgrade if you rely on that behaviour.