Download the PHP package consistence-community/consistence-jms-serializer without Composer

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

Integration of Consistence library with JMS Serializer

This package is a fork of consistence/consistence-jms-serializer maintained by community to support new PHP versions.


This library provides integration of Consistence value objects for JMS Serializer so that you can use them in your serialization mappings.

For now, the only integration which is needed is for Enums, see the examples below.

Usage

Enums represent predefined set of values and of course, you will want to serialize and deserialize these values as well. Since Enums are objects and you only want to (de)serialize represented value, there has to be some mapping.

You can see it in this example where you want to (de)serialize sex for your Users:

Now you can use the Sex enum in your User object. Type for (de)serialization is specified as enum<Your\Enum\Class>:

Now everything is ready to be used, when you serialize the object, only female will be returned as the value representing the enum:

And when you deserialize the object, you will receive the Sex enum object again:

This means that the objects API is symmetrical (you get the same type as you set) and you can start benefiting from Enums advantages such as being sure, that what you get is already a valid value and having the possibility to define methods on top of the represented values.

Nullable by default

Both serialization and deserialization will accept null values, there is no special mapping for that (by Jms Serializers convention), so if you are expecting a non-null value you have to enforce this by other means - either by restricting this in the API of your objects or by validation (needed especially for deserialization).

Invalid values

While serializing, there should be no invalid values, because Enums guarantee that the instance contains only valid values.

While deserializing, there can be an invalid value given, an exception will be thrown:

If you are using this in an API, make sure you will catch this exception and send the consumer a response detailing this error, you can also write a custom message, the available values are listed in InvalidEnumValueException::getAvailableValues().

XML support

Unlike in JSON, in XML value types cannot be inferred directly from the values. So if you need to deserialize XML, you have to provide this type manually. You can do this by writing the type in the type definition - for the above example it would be string:

Special support for mapped MultiEnums

Since the (de)serialization works only with the value the enum is representing, then in case of MultiEnums this would mean outputting the value of the internal bit mask. This could be useful if both the client and server use the same Enum objects, but otherwise this breaks the abstraction and is less readable for a human consumer as well.

If you are using a MultiEum mapped to a single Enum there is a handy solution provided, if you add to your mapping enum<Your\Enum\Class, as_single> - notice the new as_single parameter, then the value of MultiEnum will be serialized as a collection of single Enum values:

Deserialization then again works symmetrically - giving an array of single Enum values will produce a MultiEnum instance:

Installation

1) Install package consistence-community/consistence-jms-serializer with Composer:

2) Register serialization handler:

If you are using Symfony, you can instead register the handler in the config/services.yaml file:

That's all, you are good to go!


All versions of consistence-jms-serializer with dependencies

PHP Build Version
Package Version
Requires php Version ~8.0
consistence-community/consistence Version ^2.1.2
jms/serializer Version ~3.14
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 consistence-community/consistence-jms-serializer contains the following files

Loading the files please wait ....