Skip to content

Commit 61eeee9

Browse files
authored
updates for 2.0 (#16)
* updates for 2.0 * update badges * formatting
1 parent e724197 commit 61eeee9

File tree

3 files changed

+70
-21
lines changed

3 files changed

+70
-21
lines changed

.codeclimate.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,14 @@ exclude_patterns:
4545
- "src/Parser/TokenParser.php"
4646
- "tests/"
4747
- "**/vendor/"
48+
- "**/*.avsc"
49+
- "**/*.yml"
50+
- "**/*.md"
51+
- ".gitignore"
52+
- "Makefile"
53+
- "LICENSE"
54+
- "**/*.json"
55+
- "**/*.neon"
56+
- "**/*.xml"
57+
- "**/docker/"
58+
- "src/console"

README.md

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
# Avro schema generator for PHP
22
[![Actions Status](https://github.com/php-kafka/php-avro-schema-generator/workflows/CI/badge.svg)](https://github.com/php-kafka/php-avro-schema-generator/workflows/CI/badge.svg)
3-
[![Maintainability](https://api.codeclimate.com/v1/badges/937e14c63beb08885c70/maintainability)](https://codeclimate.com/github/php-kafka/php-avro-schema-generator/maintainability)
4-
[![Test Coverage](https://api.codeclimate.com/v1/badges/937e14c63beb08885c70/test_coverage)](https://codeclimate.com/github/php-kafka/php-avro-schema-generator/test_coverage)
3+
[![Maintainability](https://api.codeclimate.com/v1/badges/41aecf21566d7e9bfb69/maintainability)](https://codeclimate.com/github/php-kafka/php-avro-schema-generator/maintainability)
4+
[![Test Coverage](https://api.codeclimate.com/v1/badges/41aecf21566d7e9bfb69/test_coverage)](https://codeclimate.com/github/php-kafka/php-avro-schema-generator/test_coverage)
55
[![Latest Stable Version](https://poser.pugx.org/php-kafka/php-avro-schema-generator/v/stable)](https://packagist.org/packages/php-kafka/php-avro-schema-generator)
6-
[![Latest Unstable Version](https://poser.pugx.org/php-kafka/php-avro-schema-generator/v/unstable)](https://packagist.org/packages/php-kafka/php-avro-schema-generator)
76

87
## Installation
98
```
10-
composer require php-kafka/php-avro-schema-generator "^1.0"
9+
composer require php-kafka/php-avro-schema-generator "^2.0"
1110
```
1211

1312
## Description
14-
Since avro does not support external subschemas, this is just a small
15-
helper to unify your schemas and to create basic schemas from php classes (experimental!).
13+
This library enables you to:
14+
- Manage your embedded schema as separate files
15+
- The library is able to merge those files
16+
- The library is able to generate avsc schema from PHP classes
1617

1718
### Merging subschemas / schemas
18-
Schema template directories: directories containing avsc template files (with subschema)
19-
Output directory: output directory for the unified schema files
19+
Schema template directories: directories containing avsc template files (with subschema)
20+
Output directory: output directory for the merged schema files
2021

21-
#### Merge subschemas (code)
22+
**Console example**
23+
```bash
24+
./vendor/bin/avro-cli avro:subschema:merge ./example/schemaTemplates ./example/schema
25+
```
26+
27+
**PHP example**
2228
```php
2329
<?php
2430

@@ -35,18 +41,49 @@ $merger->merge();
3541

3642
```
3743

38-
#### Merge subschemas (command)
44+
### Merge optimizers
45+
There are optimizers that you can enable for merging schema:
46+
- FullNameOptimizer: removes unneeded namespaces
47+
- FieldOrderOptimizer: the first fields of a record schema will be: type, name, namespace (if present)
48+
49+
How to enable optimizer:
50+
51+
**Console example**
3952
```bash
40-
./vendor/bin/avro-cli avro:subschema:merge ./example/schemaTemplates ./example/schema
53+
./vendor/bin/avro-cli --optimizeFullNames --optimizeFieldOrder avro:subschema:merge ./example/schemaTemplates ./example/schema
54+
```
55+
**PHP Example**
56+
```php
57+
<?php
58+
59+
use PhpKafka\PhpAvroSchemaGenerator\Registry\SchemaRegistry;
60+
use PhpKafka\PhpAvroSchemaGenerator\Merger\SchemaMerger;
61+
use PhpKafka\PhpAvroSchemaGenerator\Optimizer\FieldOrderOptimizer;
62+
use PhpKafka\PhpAvroSchemaGenerator\Optimizer\FullNameOptimizer;
63+
64+
$registry = (new SchemaRegistry())
65+
->addSchemaTemplateDirectory('./schemaTemplates')
66+
->load();
67+
68+
$merger = new SchemaMerger($registry, './schema');
69+
$merger->addOptimizer(new FieldOrderOptimizer());
70+
$merger->addOptimizer(new FullNameOptimizer());
71+
72+
$merger->merge();
73+
4174
```
4275

4376
### Generating schemas from classes
44-
Please note, that this feature is highly experimental.
45-
You probably still need to adjust the generated templates, but it gives you a basic template to work with.
46-
Class directories: Directories containing the classes you want to generate schemas from
47-
Output directory: output directory for your generated schema templates
77+
You will need to adjust the generated templates, but it gives you a good starting point to work with.
78+
Class directories: Directories containing the classes you want to generate schemas from
79+
Output directory: output directory for your generated schema templates
4880

49-
#### Generate schemas (code)
81+
**Console example**
82+
```bash
83+
./vendor/bin/avro-cli avro:schema:generate ./example/classes ./example/schemaTemplates
84+
```
85+
86+
**PHP Example**
5087
```php
5188
<?php
5289

@@ -65,7 +102,8 @@ $generator->exportSchemas($schemas);
65102

66103
```
67104

68-
#### Merge subschemas (command)
69-
```bash
70-
./vendor/bin/avro-cli avro:schema:generate ./example/classes ./example/schemaTemplates
71-
```
105+
## Disclaimer
106+
In `v1.3.0` the option `--optimizeSubSchemaNamespaces` was added. It was not working fully
107+
in the `1.x` version and we had some discussions (#13) about it.
108+
Ultimately the decision was to adapt this behaviour fully in `v2.0.0` so you might want to
109+
upgrade if you rely on that behaviour.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"extra": {
3434
"branch-alias": {
35-
"dev-main": "2.0-dev"
35+
"dev-main": "3.0-dev"
3636
}
3737
}
3838
}

0 commit comments

Comments
 (0)