auxmoney / avro-php
Avro schema encoder/decoder
Installs: 11 194
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 2
Open Issues: 0
pkg:composer/auxmoney/avro-php
Requires
- php-64bit: >=8.2
- ext-mbstring: *
Requires (Dev)
- infection/infection: ^0.30.3
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11
- symplify/easy-coding-standard: ^12
This package is auto-updated.
Last update: 2026-01-14 14:39:31 UTC
README
A PHP library that provides schema-based Avro data serialization and deserialization.
Key features:
- Support for logical types
- Developer-friendly error messages for schema validation
- Schema resolution including promotion of primitive types
- Serialization of objects through getters or public properties
- Default values for record fields
- Configurable block count and block size for array and map encoding
Installation
To install auxmoney/avro-php, you can use Composer:
composer require auxmoney/avro-php
Usage
Encoding/Decoding Data
Try out the example scripts:
php examples/encoding.php php examples/decoding.php php examples/logical-type.php
Logical Types
It is possible to configure logical types in a few different ways:
Using Default Logical Types
There are built-in implementations for all logical types described in the AVRO specification, except for timestamp-nanos and local-timestamp-nanos, because PHP's DateTime doesn't have nanosecond precision.
To use the default logical types, simply create an AvroFactory without any options:
$avroFactory = AvroFactory::create();
Overriding Logical Types
You can override default logical types or add custom ones by providing factory implementations:
$defaultLogicalTypeFactories = AvroFactory::getDefaultLogicalTypeFactories(); $defaultLogicalTypeFactories['custom'] = new MyCustomLogicalTypeFactory(); $options = new Options(logicalTypeFactories: $defaultLogicalTypeFactories); $avroFactory = AvroFactory::create($options);
Disabling Logical Types
To disable all logical type processing and treat them as their underlying primitive types:
$options = new Options(logicalTypeFactories: []); $avroFactory = AvroFactory::create($options);
Value Objects for Logical Types
Some logical types work with their respective value objects to provide type safety and better representation of the data:
decimal:Auxmoney\Avro\ValueObject\Decimalduration:Auxmoney\Avro\ValueObject\Durationtime-millis:Auxmoney\Avro\ValueObject\TimeOfDaytime-micros:Auxmoney\Avro\ValueObject\TimeOfDayuuid:Auxmoney\Avro\ValueObject\Uuid
The local-timestamp-* and timestamp-* types are serialized from/deserialized to DateTimeInterface.
Documentation
For more detailed documentation on usage, schema design, and advanced features like schema evolution, please refer to the official Avro documentation.
Contribution
Contributions are welcome! If you find a bug or want to suggest a new feature, feel free to open an issue or submit a pull request.
Development Setup
This project uses VS Code Dev Containers for development. This ensures a consistent development environment across all contributors.
Using VS Code Dev Container (Recommended)
- Install the Dev Containers extension in VS Code
- Open the project in VS Code
- When prompted, click "Reopen in Container" or use
Ctrl+Shift+P→ "Dev Containers: Reopen in Container"
The container includes:
- PHP 8.3 with Xdebug
- Composer for dependency management
- PHPUnit for testing
- Node.js for test generation tools
- Git and GitHub CLI
Manual Docker Usage
You can also use the containers manually:
# Using the convenience script (recommended) ./docker-dev run --rm dev ./docker-dev run --rm dev vendor/bin/phpunit ./docker-dev run --rm test-generator # Or using docker compose directly docker compose -f .devcontainer/docker-compose.yaml run --rm dev docker compose -f .devcontainer/docker-compose.yaml run --rm dev vendor/bin/phpunit docker compose -f .devcontainer/docker-compose.yaml run --rm test-generator
For more details, see .devcontainer/README.md.
License
This library is licensed under the Apache License 2.0.
Changelog
For the detailed changelog, please refer to the Releases page.