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

Cbor Php Laravel Package

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.

View on GitHub
Deep Wiki
Context7

CBOR Encoder/Decoder for PHP

Frequently asked questions about Cbor Php
How do I install spomky-labs/cbor-php in a Laravel project?
Install it with composer require spomky-labs/cbor-php. The package requires PHP 8.0 or higher, ext-mbstring, and brick/math; ext-gmp or ext-bcmath are optional but recommended for large integers and Big Float or Decimal Fraction support. There is no Laravel-specific installer or auto-discovery provider, so you use the CBOR classes directly or bind them in your own service provider.
Is spomky-labs/cbor-php compatible with Laravel 10 and Laravel 11?
As a PHP 8+ library it can be used in Laravel 10 and Laravel 11 applications, but compatibility depends on your PHP version and Composer constraints rather than a Laravel package integration. It does not ship a Laravel service provider or facade, so you wire the encoder and decoder into the container yourself. Test your Laravel and PHP versions in CI before upgrading.
How do I encode and decode CBOR data in a Laravel controller?
Create CBOR objects such as MapObject, TextStringObject, and UnsignedIntegerObject, cast the root object to string to encode, and use Decoder::create()->decode(StringStream::create($payload)) to decode. Call normalize() on the decoded object to convert it to native PHP arrays and scalars. In Laravel, wrap this logic in a service, action, or middleware so controllers stay thin.
Can I use spomky-labs/cbor-php for WebAuthn or COSE data in Laravel?
The package includes built-in tag support for common CBOR tags and is suitable for WebAuthn and COSE-style binary payloads, but verify the exact tag classes and RFC coverage against your authenticator data requirements. It supports all CBOR major types, indefinite-length items, and normalization to PHP types. For Laravel, keep WebAuthn verification in a dedicated service and test with real attestation and assertion fixtures.
How do I register the CBOR decoder as a singleton in Laravel?
In a service provider's register method, bind the decoder as a singleton, for example $this->app->singleton(Decoder::class, fn () => Decoder::create()). You can bind encoder helpers similarly if your code uses an encoder abstraction. Resolve it via dependency injection in controllers, jobs, or custom casts.
How can I add CBOR request and response middleware in Laravel?
Create middleware that checks the Accept or Content-Type header for application/cbor, decodes the raw request body with the CBOR decoder, and merges the normalized array into the request. For responses, encode arrays or DTOs to CBOR and return a response with the application/cbor content type. Register the middleware globally or on API routes, and keep a JSON fallback during migration.
Does cbor-php support streaming decoding for large CBOR payloads?
Yes, the package provides a streaming decoder intended for efficient memory usage with large payloads. Use it when decoding blobs from queues, storage, or IoT-style endpoints instead of loading everything into memory at once. Benchmark with your own payload sizes and PHP memory limits in staging.
How do I create custom CBOR tags with spomky-labs/cbor-php?
Implement a custom tag class following the package's tag system and register it with the decoder so it can be recognized during decoding. The library ships built-in common tags and documents custom tag creation, which is useful for domain-specific extensions in finance, healthcare, or authentication. Audit custom tags against RFC 8949 to avoid interoperability problems.
What are the benefits of using CBOR instead of JSON in Laravel APIs?
CBOR is a compact binary format that can reduce payload size versus JSON and is useful for performance-sensitive APIs, IoT, and WebAuthn flows. The package supports tags, indefinite-length items, streaming decoding, and normalization to native PHP types. The tradeoff is that clients must support application/cbor, so use content negotiation or feature flags during migration.
How do I test CBOR encoding and decoding in Laravel with PHPUnit?
Because Decoder and related CBOR classes are plain PHP objects, you can unit test encode-decode round trips without booting Laravel. For Laravel integration, bind the decoder in the container, mock or inject it into services, and assert normalized arrays and headers in feature tests. Include fixtures for malformed CBOR, tags, and large payloads to cover error handling.
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.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
adachsoft/php-code-style