Download the PHP package joetjen/dextrin without Composer

On this page you can find all versions of the php package joetjen/dextrin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package dextrin

php-dextrin

[!WARNING] Under heavy development: not for production use before 1.0.0. Things can and will break, and the specification can and will change, between any two releases until 1.0.0. Do not use this library in a production system yet.

CI Packagist Docs

A PHP port of dextrin, an Elixir implementation of DXN (Data eXchange Notation): a human-writable text format (.dxn), a compact binary format (.dxnb) built on CBOR, and a schema format (.dxns) — all three sharing one in-memory value representation and one extension mechanism. A sibling of node-dextrin, the Node.js port of the same library.

Status: feature-complete, pre-1.0. The value model (src/Value/), the .dxn text codec, the .dxnb binary codec, the .dxns schema system, the CLI, and the guides are all implemented. See CHANGELOG.md for exactly what's landed, and the Documentation section below to get started.

Why use Dextrin?

Most serialization formats pick one point on a spectrum. JSON is human-writable but has no dates, no bytes, no exact decimals and no boundary between an integer and a float. Protobuf and Avro are compact and typed but need a schema compiled ahead of time, and aren't meant for a person to read or edit. CBOR and MessagePack are compact and self-describing but binary only. YAML and TOML are made for people, and have no binary form for machines.

DXN's premise is that a .dxn text document and a .dxnb binary document are the same value space: 31 scalar, collection, temporal and extended types (reference §1.3). It is precise enough for money (decimals), exact ratios (rationals) and integers of any size, has struct and custom-tag as first-class, schema-describable extension points, and its schemas (.dxns) are DXN too. You choose text or binary by what matters where the data is going -- a person reading it, or bytes on the wire -- and the value is the same either way.

What each format can say

DXN JSON YAML TOML BSON MessagePack CBOR Protobuf Ion
Text a person writes ✓ ✓ ✓ ✓ – – –¹ –² ✓
Binary, same values ✓ – – – ✓ ✓ ✓ ✓ ✓
Comments ✓ – ✓ ✓ – – – – ✓
Schema, part of the format ✓ ~³ – – – – – –² ~³
Readable without a schema ✓ ✓ ✓ ✓ ✓ ✓ ✓ – ✓
Integer and float kept apart ✓ – ✓ ✓ ✓ ✓ ✓ ✓ ✓
Integers beyond 64 bits ✓ ~⁴ ~⁴ – – – ✓ – ✓
Exact decimals ✓ – – – ✓ – ✓ – ✓
Exact ratios ✓ – – – – – ✓ – –
Timestamps, dates, times, durations ✓ – ~⁵ ~⁶ ~⁷ ~⁷ ~¹³ ~⁸ ~¹⁴
Bytes ✓ – ~⁵ – ✓ ✓ ✓ ✓ ✓
UUIDs, URIs ✓ – – – ~⁹ – ✓ – –
Sets, tuples ✓ – ~⁵ – – – ~¹⁰ – –
Map keys that are not strings ✓ – ✓ – – ✓ ✓ ~¹¹ –
Typed records (structs) ✓ – – – – – – ✓ –
Types an application adds ✓ – ✓ – – ✓ ✓ – ✓
Versioned schemas, checked in CI ✓ – – – – – – ~¹² –

¹ CBOR has a diagnostic notation for reading, not for authoring. ² Protobuf's text format is for debugging; its schema is a separate .proto file compiled ahead of time. ³ JSON Schema and Ion Schema are written in JSON and Ion, as separate specifications. ⁴ The grammar allows any size; JavaScript's and PHP's parsers lose the digits past 53 and 64 bits. ⁵ YAML 1.1 tags (!!timestamp, !!binary, !!set), dropped from 1.2's core schema. ⁶ Dates, times and date-times; no durations. ⁷ An instant only: no local dates, times or durations. ⁸ The well-known Timestamp and Duration messages. ⁹ A UUID as binary subtype 4. ¹⁰ Sets by registered tag 258; no tuples. ¹¹ Integer and string keys only. ¹² Field numbers keep old readers working; nothing checks a change. ¹³ Instants (tags 0 and 1) and dates (RFC 8943); no times of day or durations. ¹⁴ Timestamps of any precision, dates included; no times of day or durations.

How big it is

The same four payloads in each format, in bytes, raw and gzipped. Measured with dextrin's bench/format_sizes.exs (mix run bench/format_sizes.exs); the script says how each format writes the values it has no type for (a decimal or a date as a string in JSON, for instance).

config file API response, 100 records time series, 1,000 points record with a 4 KiB blob
DXN text 279 / 199 19,402 / 4,218 63,159 / 13,895 5,516 / 4,222
DXN text, pretty 314 / 216 23,504 / 4,249 67,161 / 13,961 5,527 / 4,234
.dxnb 264 / 210 14,185 / 3,802 34,006 / 14,381 4,145 / 4,168
.dxnb, shared 264 / 210 9,217 / 3,752 27,017 / 14,019 4,145 / 4,168
JSON 306 / 207 19,202 / 4,201 56,159 / 13,692 5,514 / 4,216
JSON, pretty 403 / 229 26,253 / 4,287 74,160 / 14,182 5,527 / 4,231
BSON 312 / 231 17,621 / 4,448 36,903 / 15,700 4,161 / 4,184
MessagePack 237 / 199 12,271 / 3,840 25,003 / 11,165 4,136 / 4,159
CBOR 237 / 188 12,282 / 3,514 25,003 / 11,164 4,136 / 4,159
Protocol Buffers 141 / 111 8,552 / 3,702 19,000 / 10,832 4,122 / 4,145

How fast it is

Decoding a document from text and checking it against a schema, timed in each implementation on the same data sets: one Universe each, about 4 KB of DXN text, against bench/schemas/universe.dxns, a 225-line schema set more complex than any one met in practice (recursion, generics, cases, refinements, formats, documents inside documents). About 30% of the data sets carry exactly one error, of 44 kinds. Each implementation ran for 90 minutes on one core of an Apple M2 Max (Elixir 1.19.5 on OTP 28 with ichor 0.7.3's parser, 2026-10-26; Node 24.18.1 and PHP 8.4.24 without opcache, 2026-10-22), and every verdict matched what the data set was meant to be. Times are per data set, in milliseconds.

data sets decode, mean decode, p99 check, mean check, p99 together, mean together, p99
Elixir 713,050 3.45 7.74 0.16 0.93 3.60 7.97
Node 4,698,138 0.53 0.85 0.54 1.02 1.07 1.80
PHP 1,316,837 1.95 2.89 0.83 1.57 2.78 4.37

Reproduce it with bench/schema-validation.php, which reads its data sets from dextrin's bench/generate_universes.exs (the script says how); the Elixir numbers come from that repository's bench/schema_validation.exs, on the very same data sets.

What comes back, in each language

What a value is after a round trip through each language's own JSON parser, and through Dextrin:

Written Elixir: JSON / Dextrin Node.js: JSON / Dextrin PHP: JSON / Dextrin Praxis: JSON / Dextrin
9223372036854775808 integer / integer 9223372036854776000 / BigInt float / DXNInteger integer / integer
19.99 as an exact decimal float / Decimal float / DXNDecimal float / DXNDecimal float / dextrin.decimal
1.0 float / float 1, an integer / float float, written back as 1 / float float / float
a datetime string / DateTime string / DXNDateTime string / DXNDateTime string / a praxis.time instant
bytes base64 string / Dextrin.Bytes base64 string / DXNBytes base64 string / DXNBytes base64 string / dextrin.bytes
a map keyed by integers string keys / integer keys string keys / integer keys string keys / integer keys string keys / integer keys
a set list / MapSet array / Set array / DXNSet vector / set

A bold entry is a value that did not come back as what was written. With Dextrin, the same document means the same thing in all four, and every implementation is held to that by the Dextrin Conformance Suite.

How DXNS compares, as a schema language

A .dxns schema is DXN data. It is meant to say everything the schema languages of the formats above can say, except what has no value or no meaning in DXN (the reference's design/schema-superset.md goes through them construct by construct). YAML, TOML and MessagePack have no schema language of their own; people use JSON Schema for them.

DXNS JSON Schema MongoDB $jsonSchema CDDL Protobuf Ion Schema
Written in the format it describes ✓ ✓ ✓ – – ✓
Typed records, with versions ✓ – – – ~¹ –
Version changes checked in CI ✓ – – – ~¹ –
Recursive types ✓ ✓ – ✓ ✓ ✓
Generic types ✓ ~² – ✓ – –
A list's items in order ✓ ✓ ✓ ✓ – ✓
A type chosen by a sibling field ✓ ~³ – ~⁴ ~⁵ –
String formats, checked the same everywhere ✓ ~⁶ – ~⁷ ~⁸ ~⁷
Decimals, ratios, dates, times, durations as types ✓ – ~⁹ ~¹⁰ – ~¹¹
Bytes holding an encoded document ✓ ✓ – ✓ – –
Annotations and free metadata ✓ ✓ ~¹² – ✓ ✓
Closing a type to unknown fields –¹³ ✓ ✓ ✓ – ✓
One test suite every implementation passes ✓ ~⁶ – – – –

¹ Field numbers keep old readers working; checking a change takes a tool outside the language, such as buf breaking. ² $dynamicRef, since draft 2020-12. ³ if/then/else; OpenAPI adds a discriminator on top. ⁴ A group choice, //, over maps with a literal member. ⁵ oneof picks one field of several, not the type of one. ⁶ The official test suite exists, but format only annotates unless a validator opts in, and each implements the formats its own way. ⁷ Regular expressions (CDDL's .regexp, Ion Schema's regex); CDDL's .abnf takes a grammar. ⁸ Through the separate protovalidate rules. ⁹ decimal and date BSON types; no times of day or durations. ¹⁰ Through tags and the prelude (tdate, decfrac); no durations. ¹¹ decimal and timestamp, with precision and offsets; no durations. ¹² title and description only. ¹³ On purpose: see the next section.

In PHP, a datetime and a local date-time range only from 1677 to 2262 (see below).

Why a DXNS type is never closed

JSON Schema's additionalProperties: false, Ion Schema's closed and CDDL's maps refuse a field the schema does not list. DXNS has no such switch, for two reasons:

A check that needs more -- say, refusing exactly the fields another schema allows -- runs after the decode, on the value it returns, where the application knows what it means.

Changing a schema across services

Several services reading and writing the same schema never all deploy at once. DXNS makes that safe with versions, not with compatibility modes (DXNS.md §8):

So a change deploys like this:

  1. A compatible change -- fields appended, nothing else -- deploys in either order.
  2. A breaking change -- a field removed, moved or retyped -- deploys readers first, each with a materializer for the old version, then the writers.
  3. A schema that services both read and write changes only compatibly, or is replaced by a new name (OrderV2) beside the old one, and the services move over one at a time.

Why a port, and why this value model

DXN's premise (see the Elixir project's own README for the full case) is that a .dxn text document and a .dxnb binary document are the same value space — scalar, collection, temporal, and extended types precise enough for money, exact ratios, and arbitrary-precision integers, with a schema-describable extension story. dxn/DXN.md is the implementation-independent, normative spec; this library only needs to satisfy it.

Where this library differs from the Elixir original — and from node-dextrin, its closest sibling — it's by design, documented at the point of difference. PHP forces some genuinely different calls than JS did: no arbitrary-precision integer natively (no GMP extension assumed available; bcmath backs the overflow case), and exactly one flexible native container (array) where JS had distinct Array/Map/Set. Notably:

Full mapping table in CHEATSHEET.md; the reasoning behind each choice is documented at the point of difference throughout src/Value/.

.dxn text

decode()/encode() throw DXNError on failure (a malformed document, or a value with no DXN representation) — idiomatic PHP from the start, not a tuple-returning API.

.dxnb binary

Hand-rolled CBOR over raw PHP strings (not built on a generic CBOR library — bignum precision, integer-only nanosecond datetimes, and the private tag block aren't things a generic library gets right by default; see src/Binary/Encoder.php's own doc). decodeBinary() accepts documents using the spec's value-sharing extensions (dxn/DXN.md §2.4/§2.5) even though encodeBinary() doesn't produce them yet — accepting is spec-mandatory, producing is optional, and that asymmetry is deliberate for now (matches the JS port).

One place .dxnb and .dxn genuinely differ: .dxnb structs are always positional on the wire, so a keyed DXNStruct round-trips through binary with its field values intact but not its keyed-ness or field names — a spec requirement, not a bug (.dxn text preserves both struct shapes exactly).

.dxns schemas

A struct/tag with no matching registry entry still falls back to an opaque DXNStruct/DXNCustomTag — a registry only ever adds capability, never turns an otherwise-valid document into an error.

encode()/encodeBinary() automatically validate every registered struct anywhere in a value by default (validate: false to skip), and a schema: name additionally validates — and, for a nameless bare array, names — the top-level value itself against one named schema.

Nothing is converted to make a value match (DXNS.md §7): a host value always means the same DXN type, with or without a schema. A plain float is a float, so a :rational field refuses it rather than turning it into a DXNRational; say which type a value is with the DXN* classes and their fromX() helpers. A field typed Point accepts only a Point struct — a DXNStruct named Point, or the class registered for it — never a bare array.

Also included, each mirroring its Dextrin.Schema.* counterpart: Schema::registerProvider() (let a class's own library ship its schema without depending on this one, see src/Schema/Provider.php), Std::registry()'s standard library of common named types (PositiveInteger, NonEmptyString, ...), and FileResolver::forPaths([...])'s resolver from names to .dxns files, by DXNS.md §6's convention, for Registry::putResolver():

Deliberate omission vs. the Elixir and JS ports: no trusted/putTrusted on Registry. Both mirror it purely to gate whether keyword decodes as an interned atom/Symbol.for (trusted) or a plain wrapper (untrusted); this port's keyword always decodes as DXNKeyword regardless, since PHP has no atom table or global symbol registry whose exhaustion untrusted input could threaten in the first place.

CLI

Documentation

Development

composer run precommit runs vendor/bin/phpstan analyse src --level=8 followed by the full PHPUnit suite — the check this project expects to pass before every commit.

See CONTRIBUTING.md for how to propose changes, and CHANGELOG.md for release history.

Installation

Other language implementations

DXN's format spec (dxn/DXN.md, ported from the Elixir project's own guides/dxn/DXN.md) is implementation-independent — this library, dextrin (Elixir), and node-dextrin all satisfy the same document, and stay close to dextrin's own in-memory shape-per-type choices wherever their host language allows.

Language Package Source
Elixir dextrin on Hex.pm joetjen/dextrin
Node.js @joetjen/dextrin on npm joetjen/node-dextrin
PHP (this project) joetjen/dextrin on Packagist joetjen/php-dextrin

License

Apache-2.0 — see LICENSE.


All versions of dextrin with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-bcmath Version *
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package joetjen/dextrin contains the following files

Loading the files please wait ...