Encode and Decode XDR strings with PHP

0.01.01 2023-11-11 01:30 UTC

This package is auto-updated.

Last update: 2024-12-11 03:56:33 UTC


README

Read and Write XDR with PHP

Latest Version on Packagist Total Downloads GitHub Actions

This package provides an implementation of the RFC 4506 External Data Representation standard for PHP. It is built to be extensible; you can encode and decode custom data objects as well as primitive generics.

This package is currently in beta; the API is still subject to change.

Important Note: Quadruple-Precision Floating-Point numbers are not supported by this package as a native type. However tools are provided for you to implement this in your own project should you have the need.

Installation

You can install the package via composer:

composer require stagerightlabs/phpxdr

Usage

use StageRightLabs\PhpXdr\XDR;

// Encode
$xdr = XDR::fresh()
    ->write(42, XDR::INT)
    ->write(3.14, XDR::FLOAT)
    ->write('Bad Wolf', XDR::STRING);

$payload = $xdr->asBase64(); // AAAAKkBI9cMAAAAIQmFkIFdvbGY=

// Decode
$xdr = XDR::fromBase64('AAAAKkBI9cMAAAAIQmFkIFdvbGY=');
$int = $xdr->read(XDR::INT); // 42
$float = $xdr->read(XDR::FLOAT); // ~3.14
$string = $xdr->read(XDR::STRING); // 'Bad Wolf'

More implementation and usage details can be found in the wiki.

Testing

./vendor/bin/phpunit

Credits

This package draws a lot of inspiration from both zulucrypto/stellar-api and stellar/js-xdr.

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email ryan@stagerightlabs.com instead of using the issue tracker.

License

The Apache License 2. Please see License File for more information.

PHP Package Boilerplate

This package was generated using the PHP Package Boilerplate by Beyond Code.