2017 © Pedro Peláez
 

library lua-serializer

A Lua serializer/deserializer

image

koesie10/lua-serializer

A Lua serializer/deserializer

  • Tuesday, December 19, 2017
  • by koesie10
  • Repository
  • 1 Watchers
  • 3 Stars
  • 209 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 12 % Grown

The README.md

PHP Lua Serializer/Deserializer

Build Version License Code Coverage Code Quality Downloads, (*1)

This is a very simple Lua serializer/deserializer for PHP, with support for JMS Serializer., (*2)

Installation

Install with Composer:, (*3)

composer require koesie10/lua-serializer

Usage

There is a facade for both serialization and deserialization:, (*4)

$result = \Vlaswinkel\Lua\Lua::serialize([ 'foo' => 'bar']);
/**
 * Returns:
 * {
 *      foo = "bar",
 * }
 */

$result = \Vlaswinkel\Lua\Lua::deserialize('{ foo = "bar" }')
/**
 * Returns:
 * [ 'foo' => 'bar' ]
 */

You can also use all the classes yourself:, (*5)

$result = \Vlaswinkel\Lua\Serializer::encode([ 'foo' => 'bar' ]); // returns the same as above

$parser = new \Vlaswinkel\Lua\Parser(new \Vlaswinkel\Lua\TokenStream(new \Vlaswinkel\Lua\InputStream('{ foo = "bar" }')));
$result = \Vlaswinkel\Lua\LuaToPhpConverter::convertToPhpValue($parser->parse()); // returns the same as above

Integration with JMS Serializer in Symfony2

This serializer can easily be included into Symfony2 with JMSSerializer, by adding the following lines to your services.yml:, (*6)

services:
    app.lua.serialization_visitor:
        class: Vlaswinkel\Lua\JMS\LuaSerializationVisitor
        arguments: ["@jms_serializer.naming_strategy"]
        tags:
            - { name: jms_serializer.serialization_visitor, format: lua }
    app.lua.deserialization_visitor:
        class: Vlaswinkel\Lua\JMS\LuaDeserializationVisitor
        arguments: ["@jms_serializer.naming_strategy"]
        tags:
            - { name: jms_serializer.deserialization_visitor, format: lua }
    app.lua.array_handler:
        class: Vlaswinkel\Lua\JMS\LuaArrayCollectionHandler
        tags:
            - { name: jms_serializer.subscribing_handler }
    app.lua.date_handler:
        class: Vlaswinkel\Lua\JMS\LuaDateHandler
        tags:
            - { name: jms_serializer.subscribing_handler }
    app.lua_constraint_violation_handler:
        class: Vlaswinkel\Lua\JMS\LuaConstraintViolationHandler
        tags:
            - { name: jms_serializer.subscribing_handler }
    app.lua.form_handler:
        class: Vlaswinkel\Lua\JMS\LuaFormHandler
        arguments: ["@translator"]
        tags:
            - { name: jms_serializer.subscribing_handler }
    app.lua_php_collection_handler:
        class: Vlaswinkel\Lua\JMS\LuaPhpCollectionHandler
        tags:
            - { name: jms_serializer.subscribing_handler }

If you want Symfony to recognize Lua as a request/response format, also add the following to your config.yml:, (*7)

framework:
    request:
        formats:
            lua: ['application/x-lua', 'application/lua']

In this case I've added application/x-lua and application/lua as MIME-types, but as there's no standard for Lua content types, these can be whatever you like., (*8)

You can now use the format lua for serialization:, (*9)

public function indexAction() {
    return $this->get('serializer')->serialize([ 'foo' => 'bar' ], 'lua');
}

Running tests

You can run automated unit tests using PHPUnit after installing dependencies:, (*10)

vendor/bin/phpunit

License

This library is licensed under the MIT license. See the LICENSE file for details., (*11)

The Versions

19/12 2017

dev-master

9999999-dev

A Lua serializer/deserializer

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Koen Vlaswinkel

parser serialization serializer deserialization lua

18/12 2017

v0.3

0.3.0.0

A Lua serializer/deserializer

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Koen Vlaswinkel

parser serialization serializer deserialization lua

07/08 2016

v0.2

0.2.0.0

A Lua serializer/deserializer

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Koen Vlaswinkel

parser serialization serializer deserialization lua

21/12 2015

v0.1

0.1.0.0

A Lua serializer/deserializer

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Koen Vlaswinkel

parser serialization serializer deserialization lua