Download the PHP package good-php/serialization without Composer

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

Good PHP serialization

The concept is similar to Moshi, a Java/Kotlin serialization library - the least effort without sacrificing customizability, support for different formats or ease of use.

This is what it can serialize and deserialize out-of-the-box:

You can then convert it into a "primitive" (scalars and arrays of scalars) or JSON:

Custom mappers

Mappers are the simplest form customizing serialization of types. All you have to do is to mark a method with either #[MapTo()] or #[MapFrom] attribute, specify the type in question as first parameter or return type and the serializer will handle the rest automatically. A single mapper may have as many map methods as you wish.

With mappers, you can even handle complex types - such as generics or inheritance:

Type adapter factories

Besides type mappers which satisfy most of the needs, you can use type adapter factories to precisely control how each type is serialized.

The idea is the following: when building a serializer, you add all of the factories you want to use in order of priority:

A factory has the following signature:

If you return null, the next factory is called. Otherwise, the returned type adapter is used.

The serialized is entirely built using type adapter factories. Every type that is supported out-of-the-box also has it's factory and can be overwritten just by doing ->addFactoryLast(). Type mappers are also just fancy adapter factories under the hood.

This is how you can use them:

In this example, NullableTypeAdapterFactory handles all nullable types. When a non-nullable type is given, it returns null. That means that the next in "queue" type adapter will be called. When a nullable is given, it returns a new type adapter instance which has two methods: serialize and deserialize. They do exactly what they're called.

Naming of keys

By default serializer preserves the naming of keys, but this is easily customizable (in order of priority):

Here's an example:

Out of the box, strategies for snake_case, camelCase and PascalCase are provided, but you it's trivial to implement your own:

Required, nullable, optional and default values

By default if a property is missing in serialized payload:

Here's an example:

Flattening

Sometimes the same set of keys/types is shared between multiple other models. You could use inheritance for this, but we believe in composition over inheritance and hence provide a simple way to achieve the same behaviour without using inheritance:

Here's an example:

Error handling

This is expected to be used with client-provided data, so good error descriptions is a must. These are some of the errors you'll get:

All of these are just a chain of PHP exceptions with previous exceptions. Besides those messages, you have all of the thrown exceptions with necessary information.

More formats

You can add support for more formats as you wish with your own type adapters. All of the existing adapters are at your disposal:

Why this over everything else?

There are some alternatives to this, but all of them will lack at least one of these:


All versions of serialization with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
php-ds/php-ds Version ^1.3.0
good-php/reflection Version ^1.0
tenantcloud/php-standard Version ^2.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 good-php/serialization contains the following files

Loading the files please wait ....