Download the PHP package anujrnair/php-json-marshaller without Composer

On this page you can find all versions of the php package anujrnair/php-json-marshaller. 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 php-json-marshaller

PHP JSON Marshaller

A library to marshall and unmarshall JSON strings to populated PHP classes, driven by annotations.

We would like fine grain control over our marshalling and unmarshalling because:

The latest version can be found here: https://github.com/AnujRNair/php-json-marshaller.

Installation

$ git clone https://github.com/AnujRNair/php-json-marshaller.git
$ composer install

Usage

In your classes, add MarshallProperty annotations to your properties and methods to describe how JSON should be marshalled or unmarshalled.

The MarshallProperty annotation requires a name and type, otherwise an exception will be thrown.

You can do this on any public property or method.

Once you have configured your class, load an instance of the JSONMarshaller class, and call the marshall or unmarshall function:

The $user variable should now be an instance of the \My\Example\User class, and be populated with the id and name we passed in from the JSON string.

The $marshalled variable will be a json encoded string holding data from the \My\Example\User object instance.

Nesting Objects

You can also nest classes within classes for recursive marshalling and unmarshalling like so:

And then in your code:

Arrays of Objects

You can marshall and unmarshall arrays of scalars/objects by indicating so in the type of the MarshallProperty annotation:

Then in your code:

Unmarshalling into Objects with a Constructor

To unmarshall into an object with a constructor, with required params, use the @MarshallCreator annotation to describe to the marshaller which values to instantiate the class with.

This Annotation takes an array of @MarshallProperty objects like the following:

The marshaller will then look for these values in the json string passed to it (The same level on which the class was instantiated) and instantiate the object with these values.

Caching

You can cache decoded classes for performance boosts. This will not cache data from JSON strings.

To do so, instantiate an instance of the Cache class, and pass in a storage type. Then pass this through to the ClassDecoder instance:

See \PhpJsonMarshaller\Cache\Storage for all storage types available. MemcachedStorage has a few options you can set as well.

Unknown Entries

You can specifically allow a class to fail on any unknown json variables by adding a MarshallConfig annotation to a specific class:

Now if you try unmarshalling an unknown variable into this class, an exception will be thrown.

Tests

Testing is covered by PHPUnit. Browse to the root of the library and run phpunit.

Please ensure you have the memcached daemon running to ensure the MemcachedStorageTest tests pass.

License

Please see the License


All versions of php-json-marshaller with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
doctrine/annotations 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 anujrnair/php-json-marshaller contains the following files

Loading the files please wait ....