2017 © Pedro Peláez
 

library php-encoder

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

image

harm-less/php-encoder

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

  • Sunday, May 8, 2016
  • by harm-less
  • Repository
  • 2 Watchers
  • 1 Stars
  • 23 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

php-encoder

Build Status, (*1)

php-encoder is a fast & flexible encoder for PHP 5.3+, (*2)

About

This library will allow you to save a snapshot of your PHP object in various formats like XML or JSON (encoding). When your project has been setup properly you can reuse the snapshot by decoding it. The decoding process will return the same PHP object you started with., (*3)

This library is useful for you if you want to quickly find a way to save a state of your PHP object. Think about a configurator that allows you to customize a certain product in various ways for example., (*4)

Getting started

  1. PHP 5.3.x is required
  2. Install php-encoder using Composer (recommended) or manually
  3. Set up the nodes you need for your PHP objects

Composer Installation

  1. Get Composer
  2. Require the encoder with composer require harm-less/php-encoder
  3. Add the following to your application's main PHP file: require 'vendor/autoload.php';

Included encoders

There are currently 2 encoding types available: XML and JSON. Both can be used interchangeably as long as you have set up your nodes correctly., (*5)

Example

Hello World - Obligatory hello world example, (*6)

foo = $value;
    }
    public function getFoo() {
        return $this->foo;
    }
}

// create a corresponding node and add the variable
class HelloWorldNode extends EncoderNode {

    function __construct() {
        parent::__construct('hello-worlds', 'hello-world', null);

        $this->addVariable(new EncoderNodeVariable('foo'));
    }
}

// register the node so it becomes known to the encoder
EncoderNode::addNode(new HelloWorldNode());

// create a HelloWorld object
$helloWorld = new HelloWorld();
$helloWorld->setFoo('hello world');

// make an instance of an encoder type and encode the object
$encoder = new XmlEncoder();
$encodedResultXml = $encoder->encode($helloWorld);

// will output:
/* 
 * <encoded>
 *   <hello-world foo="hello world"/>
 * </encoded>
 */
echo htmlentities($encodedResultXml->saveXML());

// decode the XML again
$decoded = $encoder->decode($encodedResultXml->saveXML());

// will output:
/*
 * HelloWorld Object
 * (
 *   [foo:HelloWorld:private] => hello world
 * )
 */
print_r($decoded['hello-world']);
?>

Unit Testing

This project uses PHPUnit as its unit testing framework., (*7)

The tests all live in /tests and each test extends an abstract class AbstractPETest, (*8)

To test the project, simply run composer install --dev to download a common version of PHPUnit with composer and run the tests from the main directory with phpunit or ./vendor/bin/phpunit, (*9)

Contributors

The Versions

08/05 2016

dev-master

9999999-dev https://github.com/harm-less/php-encoder

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harm van der Werf

php json xml object conversion encoding decoding encode decode object conversion

08/05 2016

0.3.0

0.3.0.0 https://github.com/harm-less/php-encoder

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harm van der Werf

php json xml object conversion encoding decoding encode decode object conversion

08/05 2016

0.2.3

0.2.3.0 https://github.com/harm-less/php-encoder

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harm van der Werf

php json xml object conversion encoding decoding encode decode object conversion

08/05 2016

0.2.2

0.2.2.0 https://github.com/harm-less/php-encoder

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harm van der Werf

php json xml object conversion encoding decoding encode decode object conversion

08/05 2016

0.2.1

0.2.1.0 https://github.com/harm-less/php-encoder

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harm van der Werf

php json xml object conversion encoding decoding encode decode object conversion

08/05 2016

0.2.0

0.2.0.0 https://github.com/harm-less/php-encoder

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harm van der Werf

php json xml object conversion encoding decoding encode decode object conversion

08/05 2016

0.1.0

0.1.0.0 https://github.com/harm-less/php-encoder

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harm van der Werf

php json xml object conversion encoding decoding encode decode object conversion

30/04 2016

0.0.4

0.0.4.0 https://github.com/harm-less/php-encoder

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harm van der Werf

php json xml object conversion encoding decoding encode decode object conversion

11/02 2016

0.0.3

0.0.3.0 https://github.com/harm-less/php-encoder

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Harm van der Werf

php json xml object conversion encoding decoding encode decode object conversion

07/02 2016

0.0.2

0.0.2.0 https://github.com/harm-less/php-encoder

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Harm van der Werf

php json xml object conversion encoding decoding encode decode object conversion

07/02 2016

0.0.1

0.0.1.0 https://github.com/harm-less/php-encoder

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harm van der Werf

php json xml object conversion encoding decoding encode decode object conversion