Download the PHP package steevanb/doctrine-read-only-hydrator without Composer

On this page you can find all versions of the php package steevanb/doctrine-read-only-hydrator. 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-read-only-hydrator

version doctrine php Lines Total Downloads Scrutinizer

doctrine-read-only-hydrator

When you retrieve data with Doctrine, you can get an array with values, or a fully hydrated object.

Hydration is a very slow process, who return same instance of entity if several hydrations have same entity to hydrate. It's fine when you want to insert / update / delete your entity. But when you just want to retrieve data without editing it (to show it in list for example), it's way to slow.

If you want to really retrieve data from your database, and don't get UnitOfWork reference : with Doctrine hydration you can't. Each query will not hydrate a new entity with data taken in your query result, it will return the first hydrated entity, known by UnitOfWork.

So, in case you don't need to modify your entity, you want to be really faster, or just retrieve data stored in your database, you can use SimpleObjectHydrator or ReadOnlyHydrator.

This hydrated entities can't be persisted / flushed, because they are not registered in UnitOfwork to be faster.

Nothing will be lazy loaded : to be faster, and because most of the time, you have to create a complete QueryBuilder, who return everything you need.

Changelog

Benchmark

This table show simple benchmark results (time and memory_get_peak_usage()), with 30, 1000 and 5000 entities retrieved from a MySQL 5.7 database, PHP 5.6.23 and Doctrine 2.5.4.

ArrayHydrator is used when you call $query->getArrayResult(), ObjectHydrator when you call $query->getResult(), $repository->findAll() or $repository->findBy().

SimpleObjectHydrator and ReadOnlyHydrator are provided with this lib, see example above.

Entities SQL request ArrayHydrator SimpleObjectHydrator ReadOnlyHydrator ObjectHydrator
30 0.26ms 1.05 ms, 28 mo 1.45 ms, 28 mo 1.78 ms, 28 mo 7.94 ms, 29 mo
1000 1.58 ms 29.75 ms, 32 mo 37.01 ms, 29 mo 43.26 ms, 32 mo 113.45 ms, 41 mo
5000 6.36 ms 164.76 ms, 48 mo 187.30 ms, 32 mo 228.89 ms, 46 mo 671.82 ms, 90 mo

You can see hydration process is really slow ! For 5 000 entities, Doctrine ObjectHydrator is 100x slower than the SQL request...

As expected, getArrayResult() is the fastest way to retrieve data. But, you have to work with array, so you can't use entity methods.

ReadOnlyHydrator is 4x faster than Doctrine ObjectHydrator, and only 40% slower than ArrayHydrator (who is hard to use).

Is you want to be as fast as possible, but with an entity result instead of an array, SimpleObjectHydrator looks pretty good.

SimpleObjectHydrator

ReadOnlyHydrator

Example

Installation

Symfony 2.x or 3.x integration

Symfony 4.x or 5.x integration

Manual integration

You need to register SimpleObjectHydrator and ReadOnlyHydrator to Doctrine\ORM\Configuration:

Integration with steevanb/doctrine-stats

steevanb/doctrine-stats add lots of statistics about Doctrine : number of mapped entities, number of lazy loaded entities, collapse and count same sql queries, show hydration time etc.

If you use this lib, you have to add SimpleObjectHydrator and ReadOnlyHydrator hydration times :


All versions of doctrine-read-only-hydrator with dependencies

PHP Build Version
Package Version
Requires php Version ^5.4.6 || ^7.0 || ^8.0
doctrine/orm Version ^2.4.8
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 steevanb/doctrine-read-only-hydrator contains the following files

Loading the files please wait ....