Download the PHP package dunglas/doctrine-json-odm without Composer

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

Doctrine JSON ODM

An Object-Document Mapper (ODM) for Doctrine ORM leveraging new JSON types of modern RDBMS.

tests Scrutinizer Code Quality StyleCI

Did you ever dream of a tool creating powerful data models mixing traditional, efficient relational mappings with modern schema-less and NoSQL-like ones?

With Doctrine JSON ODM, it's now possible to create and query such hybrid data models with ease. Thanks to modern JSON types of RDBMS, querying schema-less documents is easy, powerful and fast as hell (similar in performance to a MongoDB database)! You can even define indexes for those documents.

Doctrine JSON ODM allows to store PHP objects as JSON documents in modern, dynamic columns of an RDBMS. It works with JSON and JSONB columns of PostgreSQL (>= 9.4) and the JSON column type of MySQL (>= 5.7.8).

For more information about concepts behind Doctrine JSON ODM, take a look at the presentation given by Benjamin Eberlei at Symfony Catalunya 2016.

Install

To install the library, use Composer, the PHP package manager:

composer require dunglas/doctrine-json-odm

If you are using Symfony or API Platform, you don't need to do anything else! If you use Doctrine directly, use a bootstrap code similar to the following:

Usage

Doctrine JSON ODM provides a json_document column type for properties of Doctrine entities.

The content of properties mapped with this type is serialized in JSON using the Symfony Serializer then, it is stored in a dynamic JSON column in the database.

When the object will be hydrated, the JSON content of this column is transformed back to its original values, thanks again to the Symfony Serializer. All PHP objects and structures will be preserved.

You can store any type of (serializable) PHP data structures in properties mapped using the json_document type.

Example:

Store a graph of random object in the JSON type of the database:

Retrieve the object graph back:

Using type aliases

Using custom type aliases as #type rather than FQCNs has a couple of benefits:

You can introduce type aliases at any point in time. Already persisted JSON documents with class names will still get deserialized correctly.

Using Symfony

In order to use type aliases, add the bundle configuration, e.g. in config/packages/doctrine_json_odm.yaml:

With this, Foo objects will be serialized as:

Another option is to use your own custom type mapper implementing Dunglas\DoctrineJsonOdm\TypeMapperInterface. For this, just override the service definition:

Without Symfony

When instantiating Dunglas\DoctrineJsonOdm\Serializer, you need to pass an extra argument that implements Dunglas\DoctrineJsonOdm\TypeMapperInterface.

For using the built-in type mapper:

Limitations when updating nested properties

Due to how Doctrine works, it will not detect changes to nested objects or properties. The reason for this is that Doctrine compares objects by reference to optimize UPDATE queries. If you experience problems where no UPDATE queries are executed, you might need to clone the object before you set it. That way Doctrine will notice the change. See https://github.com/dunglas/doctrine-json-odm/issues/21 for more information.

FAQ

What DBMS are supported?

PostgreSQL 9.4+ and MySQL 5.7+ are supported.

Which versions of Doctrine are supported?

Doctrine ORM 2.6+ and DBAL 2.6+ are supported.

How to use the JSONB type of PostgreSQL?

Then, you need to set an option in the column mapping:

Does the ODM support nested objects and object graphs?

Yes.

Can I use the native PostgreSQL and MySQL /JSON functions?

Yes! You can execute complex queries using native queries.

Alternatively, install scienta/doctrine-json-functions to be able to use run JSON functions in DQL and query builders.

How to change the (de)serialization context

You may need to change the (de)serialization context, for instance to avoid escaping slashes.

If you are using Symfony, modify your Kernel like this:

How can I add additional normalizers?

The Symfony Serializer is easily extensible. This bundle registers and uses a service with ID dunglas_doctrine_json_odm.serializer as the serializer for the JSON type. This means we can easily override it in our services.yaml to use additional normalizers. As an example we inject a custom normalizer service. Be aware that the order of the normalizers might be relevant depending on the normalizers you use.

When the namespace of a used entity changes

For classes without type aliases, because we store the #type along with the data in the database, you have to migrate the already existing data in your database to reflect the new namespace.

Example: If we have a project that we migrate from AppBundle to App, we have the namespace AppBundle/Entity/Bar in our database which has to become App/Entity/Bar instead.

When you use MySQL, you can use this query to migrate the data:

Credits

This bundle is brought to you by Kévin Dunglas and awesome contributors. Sponsored by Les-Tilleuls.coop.

Former Maintainers

Yanick Witschi helped maintain this bundle, thanks!


All versions of doctrine-json-odm with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
doctrine/orm Version ^2.6.3 || ^3.0.0
symfony/property-access Version ^5.4 || ^6.0 || ^7.0
symfony/property-info Version ^5.4 || ^6.0 || ^7.0
symfony/serializer Version ^5.4 || ^6.0 || ^7.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 dunglas/doctrine-json-odm contains the following files

Loading the files please wait ....