Skip to content

Latest commit

History

44 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

transit-php CircleCI

Transit is a data format and a set of libraries for conveying values between applications written in different languages. This library provides support for marshalling Transit data to/from PHP. Unlike the Java and Clojure implementations it relies on the non-streaming JSON parsing mechanism of the host PHP environment.

This implementation's major.minor version number corresponds to the version of the Transit specification it supports.

NOTE: Transit is a work in progress and may evolve based on feedback. As a result, while Transit is a great option for transferring data between applications, it should not yet be used for storing data durably over time. This recommendation will change when the specification is complete.

Installation

composer require honzabrecka/transit-php

Usage

usetransit\JSONReader;
usetransit\JSONWriter;
usetransit\Transit;
usetransit\Map;
$transit = newTransit(newJSONReader(), newJSONWriter());
$transit->read('["^ ","foo","bar"]');
$transit->write(newMap(['foo', 'bar']));

You can use assoc array instead of transit\Map. It comes with a price (string keys only), therefore it's disabled by default.

usetransit\JSONReader;
usetransit\JSONWriter;
usetransit\Transit;
$transit = newTransit(newJSONReader(true), newJSONWriter(true));
$transit->read('["^ ","foo","bar"]');
$transit->write(['foo' => 'bar']);

Default Type Mapping

Transit typeWrite acceptsRead returns
nullnullnull
stringstringstring
booleanboolbool
integerintint
decimalfloatfloat
bytestransit\Bytestransit\Bytes
keywordtransit\Keywordtransit\Keyword
symboltransit\Symboltransit\Symbol
timeDateTimeDateTime
arrayarrayarray
maptransit\Map or assoc arraytransit\Map or assoc array
cmaptransit\CMaptransit\CMap
settransit\Settransit\Set
listSplDoublyLinkedListSplDoublyLinkedList
uritransit\URItransit\URI
uuidtransit\UUIDtransit\UUID
chartransit\Chartransit\Char

About

Transit for PHP

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages