spomky-labs/cbor-php
RFC 8949 CBOR encoder/decoder for PHP 8+. Supports all major types, tags, indefinite-length items, streaming decoding, and normalization to native PHP types. Extensible tag system with built-in common tags and modern, type-safe API.
Normalizable interfaces) and integrates seamlessly with Laravel’s dependency injection and service container.AppServiceProvider for global access.Illuminate\Http\Middleware).brick/math for big integers, optional ext-gmp/ext-bcmath). No conflicts with Laravel’s core dependencies.Decoder, Encoder) simplify unit testing for CBOR-based logic (e.g., WebAuthn assertions).| Risk Area | Mitigation Strategy |
|---|---|
| Performance Overhead | Benchmark against JSON/XML in staging. Use ext-gmp for large integers if needed. |
| Streaming Decoder | Test with large payloads (>1MB) to validate memory efficiency in edge cases. |
| Tag Compatibility | Audit custom tags against RFC 8949 to avoid interoperability issues. |
| PHP Version | Enforce PHP 8.0+ in CI/CD (already required by the package). |
| BCMath/GMP Dependency | Fallback to brick/math if extensions are unavailable (package handles this). |
Tag\TimestampTag and Tag\CoseKeyTag; for IoT, prioritize streaming decoder.normalize() for seamless conversion.Accept: application/cbor header).Validator::extend('cbor', fn ($attribute, $value, $parameters) => ...)).bytea or MySQL’s BLOB; use Eloquent accessors to serialize/deserialize.// Model
protected $casts = ['cbor_data' => CBORCast::class];
Tag\CoseKeyTag and Tag\WebAuthnAssertionTag./api/v1/data).Accept header negotiation).Response::json() and Response::binary() to serve appropriate formats.^3.2 in composer.json to avoid breaking changes (e.g., brick/math updates).| Step | Dependency | Owner |
|---|---|---|
1. Add CBOR to composer.json |
None | Backend Team |
2. Create CBORService |
Laravel Service Container | Backend Team |
| 3. Implement middleware | CBORService |
Backend Team |
| 4. Pilot endpoint | Middleware + Test Data | QA/Backend |
| 5. Benchmark vs. JSON | k6/Laravel Telescope | DevOps |
| 6. Roll out to core APIs | Feature flag | Backend Team |
| 7. Update database models | Eloquent Accessors | Backend Team |
| 8. Migrate queue jobs | Laravel Queues | Backend Team |
| 9. Deprecate JSON fallback | Analytics data | Product/Backend |
brick/math and spomky-labs/cbor-php for security patches (e.g., via GitHub Dependabot).3.2.x → 3.3.x).config/cbor.php file) for consistency.cbor-js for browser clients.StringStream class to inspect CBOR payloads in logs (e.g., base64_encode((string) $cborObject)).CborFallbackException to gracefully degrade to JSON when CBOR fails.StringStream with chunked reading for memory efficiency.bytea with cbor operator class for efficient indexing of CBOR blobs.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Malformed CBOR payload | 5xx errors | Validate input with `try-c |
How can I help you explore Laravel packages today?