Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Avro Serde Php Laravel Package

mateusjunges/avro-serde-php

Avro SerDe library for PHP 7.3+ and 8.0 that implements the Confluent wire format and integrates a cached Schema Registry client, so you can serialize and deserialize Avro messages while keeping schema evolution compatible with downstream consumers.

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer: composer require mateusjunges/avro-serde-php. As of v3.1.0 the package requires PHP 8.1+, flix-tech/avro-php ^5.1, and (for registry work) mateusjunges/confluent-schema-registry-api — pin that to 9.1.0 or later if you want Guzzle 8 support.

Next, review the README — it provides a minimal Symfony Serializer setup example. The primary entry point is the AvroSerializer class, which integrates with Symfony’s Serializer component (pulled into Laravel via symfony/serializer). To serialize/deserialize an object, define your schema (JSON file or inline string), load it into an AvroSchema, and pass both the schema and your object to the AvroSerializer. The first common use case is serializing domain objects to Avro binary for Kafka producers or a schema registry.

If you are on Laravel 9/10 with an older PHP constraint, verify your composer.json platform requirement before upgrading — v3.1.0 will not install on PHP 8.0.

Implementation Patterns

  • Schema Management: Store Avro schemas in versioned files (e.g., schemas/user.avsc) and load them via AvroSchema::loadJsonFile() or use inline schema strings for simple cases.
  • Service Container Wiring: Bind AvroSerializer (and SchemaRegistrySerializer) as singletons in a service provider so the parsed Schema graph and the Guzzle/PSR-18 HTTP client are reused across requests and jobs.
  • Symfony Serializer Stack: Register AvroSerializer as a normalizer/encoder and tag it appropriately if you are using the full Symfony Serializer; in Laravel, resolve it from the container rather than instantiating per call.
  • Schema Registry Workflow: Use SchemaRegistrySerializer to resolve schema IDs dynamically from a remote registry (e.g., Confluent Schema Registry). With v3.1.0 you can now run on Guzzle 8 (guzzlehttp/promises ^3.0) provided the registry client is on 9.1.0+; cache schema lookups using Laravel’s cache repository for performance.
  • Typed Payloads: Define plain PHP objects (DTOs) with typed properties (public string $name;) and let the serializer handle conversion and validation based on the Avro schema.
  • Testing: Mock the serializer and validate round-trip integrity by deserializing previously serialized binary data; compare domain objects field-by-field. Add a CI matrix row on PHP 8.1 and PHP 8.4 to catch the nullable-parameter class of deprecations fixed in this release.

Gotchas and Tips

  • PHP Version Floor: v3.1.0 raised the minimum to PHP 8.1 and merged upstream flix-tech/avro-serde-php changes. If you are still on 8.0, stay on 3.0.x or upgrade the runtime first.
  • Guzzle 8 Support Is Conditional: guzzlehttp/promises ^3.0 is allowed, but Guzzle 8 compatibility flows through mateusjunges/confluent-schema-registry-api 9.1.0. Upgrading Guzzle without bumping the registry client will leave you with an unresolvable dependency set — bump both together and re-run your HTTP client bindings.
  • PHP 8.4 Deprecations: AvroNameConverter had implicitly nullable parameters, fixed in v3.1.0. If you forked or subclassed that converter, re-check your signature (?Type $x = null rather than Type $x = null).
  • Transitive Constraint Changes: widmogrod/php-functional ^7.0 is now permitted and flix-tech/avro-php must be ^5.1. Run composer why widmogrod/php-functional after upgrading if you have other packages pinning ^6.x — Composer may resolve to an older avro-serde if constraints conflict.
  • Schema Compatibility: Avro resolution is strict by default — writer/reader mismatches (missing fields, type changes) raise SchemaResolutionException. Use defaults and unions (["null","string"]) for forward/backward compatibility.
  • Binary vs String Encoding: Output is raw binary by default. Pass false to AvroSerializer::encode() for Kafka payloads and true for base64 when debugging or logging.
  • Performance: Parse each schema once and cache the Schema instance. In long-running workers (Horizon, Octane, queue daemons) hold schemas in singletons/static properties and remember the registry client’s connection is also long-lived.
  • No PHP 8 Attributes: This package does not read attributes or annotations from your classes — serialization behaviour comes solely from the Avro schema. Do not expect #[AvroName]-style hints to work.
  • Debugging Errors: Attach a PSR-3 logger via AvroSerializer::setLogger() to capture resolution failures; messages typically name the expected vs. actual field and type, which is usually enough to locate the schema drift.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings