Download the PHP package liip/serializer without Composer

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

Liip Serializer - A fast JSON serializer

This project is Open Sourced based on work that we did initially as closed source at Liip, it may be lacking some documentation. We plan to add more documentation and support, including Symfony bundles in the near future. If there is anything that you need or have questions about we would love to see you open an issue! :)

What it supports

This serializer can convert between JSON and PHP objects and back. It uses reflection, Phpdoc and JMS Serializer annotations to generate PHP code for the conversion. JMS serializer groups and versions are supported for serializing but not for deserializing.

Limitations

If you customized JMS Serializer with your own listeners or similar things, this serializer will not work for you. We made an effort to detect when unsupported features are used and raise an error, but recommend that you double check whether the Liip Serializer really produces the exact same as JMS when transforming your data.

How it works

The Liip Serializer generates PHP code based on the PHP models that you specify. It uses the flexible liip/metadata-parser to gather metadata on the models. A separate file is generated for every version and serializer groups combination to move all logic to the code generation step. This serializer is fast even for massive object trees because the generated PHP code is very simplistic and specific to the usecase, rather than the complex, flexible callback structure that JMS serializer uses. The project we developped this for often has data with up to a megabyte of compact JSON data.

You can use the Liip Serializer stand alone. If you are already working with JMS Serializer, you can also use the drop-in replacement for JMS serializer liip/serializer-jms-adapter. The drop-in adapter implements the JMS interfaces and provides fallback to the regular JMS serializer for missing generated files and on other errors.

How to use it

You need to generate converter files whenever your models change. They follow a naming scheme that allows the Liip Serializer to find them. Because the files have to be pre-generated, you need to specify the exact list of classes, serializer groups and versions you want to support.

Note: We plan to create a Symfony bundle to integrate the Liip Serializer into Symfony.

Generate your files

This step needs to be executed during the deployment phase and whenever your models change.

Configuration format

Specify global defaults for the versions to be generated, and the group combinations.

Then specify for which classes to generate the serializer and deserializer.

For each class, you can overwrite which versions to generate. If you specify no group combinations, the global default group combinations are used. If you specify group combinations, you can again overwrite the versions to generate.

Note that defaults are not merged - the most specific list is used exclusively.

Version

To generate a file without version, specify version '' in the list of versions.

Groups

To generate a serializer without groups, specify an empty group combination [].

Arrays with an unknown type

If you want to (de)serialize arrays with undefined content, you can do that by setting the allow_generic_arrays value to true via the options argument.

Note: This will only work if the contents of that array are only primitive types (string, int, float, boolean and nested arrays with only these types).

Serialize using the generated code

In this example, we serialize an object of class Product for version 2:

Deserialize using the generated code

Working with Arrays

Like JMS Serializer, the Liip Serializer also provides fromArray and toArray for working with array data. As usual when using PHP arrays for JSON data, you will lose the distinction between empty array and empty object.

Where do I go for help?

If you need help, please open an issue on github.

Background: Why an Object Serializer Generator?

We started having performance problem with large object structures (often several Megabyte of JSON data). Code analysis showed that a lot of time is spent calling the JMS callback structure hundred thousands of times. Simplistic generated PHP code is much more efficient at runtime.

Implementation Notes

The DeserializerGenerator and SerializerGenerator produce PHP code from the metadata. The generators use twig to render the PHP code, for better readability. See the Template namespace.

The indentation in the generated code is not respecting levels of nesting. We could carry around the depth and prepend whitespace, but apart from debugging, nobody will look at the generated code.

We decided to not use reflection, for better performance. Properties need to be public or have a public getter for serialization. For deserialization, we also match constructor arguments by name, so as long as a non-public property name matches a constructor argument, it needs no setter.


All versions of serializer with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-json Version *
liip/metadata-parser Version ^1.2
pnz/json-exception Version ^1.0
symfony/filesystem Version ^4.4 || ^5.0 || ^6.0 || ^7.0
symfony/finder Version ^4.4 || ^5.0 || ^6.0 || ^7.0
symfony/options-resolver Version ^4.4 || ^5.0 || ^6.0 || ^7.0
twig/twig Version ^2.7 || ^3.0
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 liip/serializer contains the following files

Loading the files please wait ....