spomky-labs/cbor-php
Comprehensive PHP 8+ CBOR (RFC 8949) encoder/decoder with full major type support, extensible tags, streaming decoding, indefinite-length handling, and normalization to native PHP types; includes common tags and custom tag support.
Normalizable interface) and enforces strict type handling, reducing runtime errors in Laravel’s strongly typed ecosystem.Carbon timestamps, Eloquent relationships).ext-mbstring (Laravel core dependency) and brick/math (lightweight, no conflicts).ext-gmp/ext-bcmath improve performance for large integers/decimals (useful for financial or cryptographic data).binary columns in MySQL/PostgreSQL).| Risk Area | Mitigation Strategy |
|---|---|
| Learning Curve | Laravel teams familiar with JSON/serialization will need training on CBOR’s binary nature and tag system. Solution: Document use cases (e.g., "CBOR for API payloads") and provide Laravel-specific examples. |
| Tooling Gaps | Lack of native Laravel integrations (e.g., no cbor:encode Artisan command). Solution: Build a facade (e.g., Cbor::encode($data)) or publish a Laravel package wrapper. |
| Performance Overhead | CBOR parsing may be slower than JSON for simple cases. Solution: Benchmark and reserve for high-value use cases (e.g., IoT, cryptography). |
| Debugging Complexity | Binary data is harder to debug than JSON. Solution: Add a Cbor::prettyPrint($encoded) helper for human-readable output. |
| Backward Compatibility | Breaking changes in CBOR specs (e.g., new tags) could affect Laravel apps. Solution: Pin to a stable version (e.g., ^1.0) and monitor RFC updates. |
json_decode equivalents).UserTag for Eloquent models)? If so, document the process for creating/extending tags.JsonToCbor converter for gradual adoption.InvalidCborException).app()->singleton(Cbor::class, fn() => new Cbor())).Accept: application/cbor).JsonResource to support CBOR serialization.Cbor trait to models for serializing attributes (e.g., protected $cborAttributes = ['metadata']).whereCborContains() method for binary columns.Cache::put($key, $cborEncodedData, $seconds).Cbor::fromJson($json) for migration).laravel-cbor package on Packagist for shared adoption.cbor-js needed).| Component | Compatibility Notes |
|---|---|
| PHP 8.0+ | Fully supported. Laravel 9+ aligns perfectly. |
| Laravel 9/10 | No conflicts. Use spomky-labs/cbor-php:^1.0 for stability. |
| Composer | Standard composer require installation. |
| Existing Code | JSON-based code remains unchanged until explicitly migrated. |
| Third-Party | Ensure client/server libraries support CBOR (e.g., cbor-js for frontend). |
spomky-labs/cbor-php to composer.json.ext-gmp, ext-bcmath) if targeting performance-critical paths.AppServiceProvider.Cbor facade for consistency with Laravel’s Json facade.Accept: application/cbor support via middleware.CBOR.md guide to the Laravel app’s docs.spomky-labs/cbor-php for breaking changes (semver compliance).composer update and test thoroughly.config/cbor_tags.php).Cbor::debug($encoded) method to inspect binary data.cbor-js) and documentation.How can I help you explore Laravel packages today?