Download the PHP package sspat/doctrine-nullable-embeddables without Composer

On this page you can find all versions of the php package sspat/doctrine-nullable-embeddables. 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 doctrine-nullable-embeddables

Nullable embeddables for Doctrine

As soon as you start using embeddable value objects in your Doctrine entities there is chance you will run in the problem, that Doctrine will instantiate value objects even when the corressponding value in the database is null. This will lead to typing-related PHP errors.

Basic example:

If you want to use PHP 7.4 typed properties:

This problem was discussed in the doctrine/orm repository issue: https://github.com/doctrine/orm/issues/4568

The current consensus is that this feature will land in the 3.x versions only.

So this leaves you with the following options:

Make your value objects properties nullable.

This will break the entity and value objects invariants and introduce a lot of unnecessary checks in your code:

Use a Doctrine lifecycle callback to reset the entity properties to null after hydration.

You will still need to set the value object's properties as nullable to avoid errors during hydration and your nullable value objects will need some logic, for example implement a special interface, to allow the lifecycle callback to determine whether the hydrated value is null or not.

You will also need to configure each nullable value object for each entity to avoid running the lifecycle callback for all entity properties.

If you choose this path, there is an implementation available: https://github.com/tarifhaus/doctrine-nullable-embeddable

Fork Doctrine to implement your own hydration mechanism

This is pretty straightforward and the implications will be in maintaining your own fork and keeping up with the upstream changes.

Override specific Doctrine classes with your own

This is what this package is doing.

It will install doctrine/orm of a specific version. The version is always the same as of this package and is locked by it, so if you want to update Doctrine you will need to update this package to the same version as the Doctrine version you want. This locking is needed to ensure that there are no changes to the files this package is patching.

After installing doctrine/orm, a patch will be applyed to the Doctrine class Doctrine/ORM/Mapping/ReflectionEmbeddedProperty using https://github.com/cweagans/composer-patches.

You can review the contents of this patch in patch/nullable_embeddables.patch

It works by analyzing the types of the properties of the entity and the value-object. If the entity property containing the value-object is declared as nullable and none of the value-object's properties that are not declared nullable get null values from the database - then the entity property will be hydrated with the value object. All other cases are considered an invalid state based on the provided typing and will result in hydrating to null on the corresponding property of the entity.

The tradeoffs of this approach will be:

A working example would look like this:

If you choose this path, you can install this package in the following steps:

Then depending on the version of doctrine/orm you want to use:


All versions of doctrine-nullable-embeddables with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
cweagans/composer-patches Version ^1.6|^1.7
doctrine/orm Version 3.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 sspat/doctrine-nullable-embeddables contains the following files

Loading the files please wait ....