2017 © Pedro Peláez
 

library leon

LEON serialization for PHP.

image

leon/leon

LEON serialization for PHP.

  • Thursday, August 6, 2015
  • by raypulver
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

phpleon

This is the PHP implementation of LEON. It works identically to the JavaScript version, except it exposes the functions leon_encode and leon_decode. A Channel object can be constructed by calling new LEON\Channel($template). A Channel object contains an encode and a decode method, which can be used to serialize data according to the template. Type constants to be passed to a LEON\Channel are defined at the top of leon.php., (*1)

Usage

require_once 'leon.php';
$payload = array(
  'firstkey' => 5,
  'secondkey' => true,
  'thirdkey' => 'just a string'
);
leon_decode(leon_encode($payload)) == $payload;
// true

LEON provides special classes to serialize/deserialize special JavaScript values. The LEON\Date constructor accepts a timestamp which can be accessed via $date->timetamp. The LEON\RegExp constructor accepts a string representation of the RegExp (without the delimiting slashes) and can also take a second argument representing the RegExp modifiers. A RegExp object stores the match pattern in $regexp->pattern and the modifier in $regexp->modifier. A RegExp object also has a toString() method which behaves identically to JavaScript's RegExp#toString()., (*2)

The value of NaN is deserialized into an instance of LEON\NaN and undefined deserializes to an instance of LEON\Undefined. If you want to serialize/deserialize a Buffer object you must use the LEON\StringBuffer class, which provides all the methods that a Node.js Buffer provides for reading and writing data., (*3)

In addition to arrays, you can also serialize objects, but only public properties will be serialized, and it will treat the data as an associative array., (*4)

If you want to create a template to be passed to LEON\Channel dynamically, you can pass an example value of the data you wish to serialize to LEON\Channel::toTemplate., (*5)

License

MIT, (*6)

The Versions

06/08 2015

dev-master

9999999-dev

LEON serialization for PHP.

  Sources   Download

The Requires

  • php >=5.3.0