Add new code generator from AVRO to PHP#3708
Conversation
…o add-schema-to-php-generator
There was a problem hiding this comment.
Pull request overview
This PR adds a PHP code-generation pipeline to the Avro PHP implementation, including a new avro CLI command, a schema-to-PHP code generator, and a “specific” datum writer for serializing generated classes.
Changes:
- Add
AvroCodeGenerator(schema → PHP records/enums) andGenerateCommand+lang/php/bin/avroCLI entrypoint. - Add
AvroSpecificDatumWriterto serialize generated record objects/enums to Avro binary. - Add PHPUnit coverage and fixtures; update PHP tooling config (PHPStan/CS Fixer) and CI paths; add new Composer dependencies.
Reviewed changes
Copilot reviewed 18 out of 30 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| lang/php/test/Generator/AvroCodeGeneratorTest.php | Adds extensive unit tests asserting generated PHP output for many schema shapes |
| lang/php/test/Fixtures/Schemas/user.avsc | Fixture schema for CLI generation tests (record) |
| lang/php/test/Fixtures/Schemas/status.avsc | Fixture schema for CLI generation tests (enum) |
| lang/php/test/Fixtures/Generated/User.php | Generated-class fixture used by specific writer tests |
| lang/php/test/Fixtures/Generated/Team.php | Generated-class fixture used by specific writer tests |
| lang/php/test/Fixtures/Generated/Task.php | Generated-class fixture used by specific writer tests |
| lang/php/test/Fixtures/Generated/Profile.php | Generated-class fixture used by specific writer tests |
| lang/php/test/Fixtures/Generated/Priority.php | Generated-enum fixture used by specific writer tests |
| lang/php/test/Fixtures/Generated/Order.php | Generated-class fixture used by specific writer tests |
| lang/php/test/Fixtures/Generated/Metadata.php | Generated-class fixture used by specific writer tests |
| lang/php/test/Fixtures/Generated/Member.php | Generated-class fixture used by specific writer tests |
| lang/php/test/Fixtures/Generated/FuelType.php | Generated-enum fixture used by specific writer tests |
| lang/php/test/Fixtures/Generated/Car.php | Generated-class fixture used by specific writer tests |
| lang/php/test/Fixtures/Generated/Address.php | Generated-class fixture used by specific writer tests |
| lang/php/test/Datum/AvroSpecificDatumWriterTest.php | Adds round-trip and byte-equivalence tests for the new specific writer |
| lang/php/test/Console/GenerateCommandTest.php | Adds Symfony Console command tests for the generator CLI |
| lang/php/README.md | Documents the new code generation CLI usage and output |
| lang/php/phpstan.neon | Includes bin/ in PHPStan scan paths |
| lang/php/lib/Schema/AvroSchema.php | Fixes JSON decoding usage and wraps JSON parse errors in AvroSchemaParseException |
| lang/php/lib/Schema/AvroNamedSchema.php | Exposes short name() accessor for named schemas |
| lang/php/lib/Schema/AvroName.php | Exposes short name() accessor for schema names |
| lang/php/lib/Schema/AvroEnumSchema.php | Adds return types / minor signature tightening for enum helpers |
| lang/php/lib/Generator/AvroCodeGeneratorException.php | Adds generator-specific exception type |
| lang/php/lib/Generator/AvroCodeGenerator.php | Implements schema traversal + PHP AST generation via nikic/php-parser |
| lang/php/lib/Datum/AvroSpecificDatumWriter.php | Implements object-based datum writing according to schema |
| lang/php/lib/Console/GenerateCommand.php | Adds generate console command for file/directory schema inputs |
| lang/php/bin/avro | Adds a composer-bin CLI entrypoint for the generator |
| lang/php/.php-cs-fixer.dist.php | Includes bin/ in code style fixer scope |
| composer.json | Adds nikic/php-parser + symfony/console, registers the avro binary, updates archive include list |
| .github/workflows/test-lang-php.yml | Narrows path filters to PHP-relevant paths and bumps Composer tool version |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
There was a problem hiding this comment.
Please add some documentation about the purpose of this file.
There was a problem hiding this comment.
Do you want to add some docs here? Because I added some instructions in the README
| return Command::FAILURE; | ||
| } | ||
|
|
||
| if (!is_dir($outputDir) && !mkdir($outputDir, 0744, true) && !is_dir($outputDir)) { |
There was a problem hiding this comment.
| if (!is_dir($outputDir) && !mkdir($outputDir, 0744, true) && !is_dir($outputDir)) { | |
| if (!is_dir($outputDir) && !mkdir($outputDir, 0755, true) && !is_dir($outputDir)) { |
Any reason to not allow group+other to cd into the created folders ?
|
|
||
| return Command::FAILURE; | ||
| } | ||
| $files = glob(rtrim($directory, '/').'/*.avsc') ?: []; |
There was a problem hiding this comment.
Would it be useful to support recursive glob here ? I.e. to look in sub-folders too ?
There was a problem hiding this comment.
I've added a recursive iterator (with a test)
What is the purpose of the change
Adds an Avro to PHP code generator and
AvroSpecificDatumWriterto serialise autogenerated classes in AvroVerifying this change
New feature with new tests
Documentation