PHPackages                             webchemistry/doctrine-hydration - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. webchemistry/doctrine-hydration

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

webchemistry/doctrine-hydration
===============================

v1.0.2(7y ago)21302PHPPHP &gt;= 7.2CI failing

Since Nov 16Pushed 5mo ago3 watchersCompare

[ Source](https://github.com/WebChemistry/doctrine-hydration)[ Packagist](https://packagist.org/packages/webchemistry/doctrine-hydration)[ RSS](/packages/webchemistry-doctrine-hydration/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (5)Versions (4)Used By (0)

[![](https://camo.githubusercontent.com/1fd993e8e25b314fe7ed667fe1ed0fc0daa897476761aa6fa34c4b7e810c9187/68747470733a2f2f686561746261646765722e76657263656c2e6170702f6769746875622f726561646d652f636f6e74726962757474652f6879647261746f722f3f646570726563617465643d31)](https://camo.githubusercontent.com/1fd993e8e25b314fe7ed667fe1ed0fc0daa897476761aa6fa34c4b7e810c9187/68747470733a2f2f686561746261646765722e76657263656c2e6170702f6769746875622f726561646d652f636f6e74726962757474652f6879647261746f722f3f646570726563617465643d31)

 [![](https://camo.githubusercontent.com/a8b1cd856d7d396fdebbe46947cc3507490acc267a02361e5e53bb7b820c95c3/68747470733a2f2f62616467656e2e6e65742f62616467652f737570706f72742f6769747465722f6379616e)](https://bit.ly/ctteg) [![](https://camo.githubusercontent.com/86d6416fc04f8bcc3daa7bf881526b9953b9726b1164d05c157c8713e3a73418/68747470733a2f2f62616467656e2e6e65742f62616467652f737570706f72742f666f72756d2f79656c6c6f77)](https://bit.ly/cttfo) [![](https://camo.githubusercontent.com/5d170ab94e6d594609561e16fe0f9e4293968fbd4dfcfafc5e11efc1415ef09c/68747470733a2f2f62616467656e2e6e65742f62616467652f73706f6e736f722f646f6e6174696f6e732f463936383534)](https://contributte.org/partners.html)

 Website 🚀 [contributte.org](https://contributte.org) | Contact 👨🏻‍💻 [f3l1x.io](https://f3l1x.io) | Twitter 🐦 [@contributte](https://twitter.com/contributte)

Disclaimer
----------

[](#disclaimer)

⚠️This project is no longer being maintained.Composer[`nettrine/hydrator`](https://packagist.org/packages/nettrine/hydrator)Version[![](https://camo.githubusercontent.com/a8aefda939bdc2a94b961dc4cb3a4e21148252c011ec60fa54878b353a6ea5c9/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f6e65747472696e652f6879647261746f72)](https://camo.githubusercontent.com/a8aefda939bdc2a94b961dc4cb3a4e21148252c011ec60fa54878b353a6ea5c9/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f6e65747472696e652f6879647261746f72)PHP[![](https://camo.githubusercontent.com/79ce8fa06e8a028dbb5f21df035dfca5baed1aee407e21debe1e6866b6373d15/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f6e65747472696e652f6879647261746f72)](https://camo.githubusercontent.com/79ce8fa06e8a028dbb5f21df035dfca5baed1aee407e21debe1e6866b6373d15/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f6e65747472696e652f6879647261746f72)License[![](https://camo.githubusercontent.com/5223d8e02c0e755f1832d8f282e3e6b3586d4c1b8e4fbfc41543e7f28c32bcc0/68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6963656e73652f636f6e74726962757474652f6879647261746f72)](https://camo.githubusercontent.com/5223d8e02c0e755f1832d8f282e3e6b3586d4c1b8e4fbfc41543e7f28c32bcc0/68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6963656e73652f636f6e74726962757474652f6879647261746f72)Usage
-----

[](#usage)

### Nette installation

[](#nette-installation)

```
extensions:
    hydrator: Nettrine\Hydrator\DI\HydratorExtension
```

### Basic usage

[](#basic-usage)

```
$entity = $hydrator->toFields(Entity::class, [
	'name' => 'foo',
	'field' => 'value',
]);

$entity = $hydrator->toFields($entityObj, [
	'name' => 'foo',
	'field' => 'value',
]);
```

### Entity to an array

[](#entity-to-an-array)

```
$array = $hydrator->toArray($entity);
```

### Custom ArrayAccessor

[](#custom-arrayaccessor)

Used to read from or write to an object's property.

```
class CustomPropertyAccessor implements IPropertyAccessor {

	public function get(object $object, string $property) { ... }

	public function set(object $object, string $property, $value): void { ... }

}
```

Nette registration:

```
hydrator:
    propertyAccessor: CustomPropertyAccessor
```

### Adapters

[](#adapters)

Do you have custom rules of getting or setting an object's value? The existing features don't suit your needs? Adapters can be used to extend the functionality.

All the adapters have to be registered via `addFieldAdapter` or `addArrayAdapter` methods.

In Nette:

```
hydrator:
    adapters:
        fields:
            - Nettrine\DoctrineHydration\Adapters\CallbackFieldAdapter
            - Nettrine\DoctrineHydration\Adapters\TargetEntityFieldAdapter
        array:
            - Nettrine\DoctrineHydration\Adapters\JoinArrayAdapter
            - Nettrine\DoctrineHydration\Adapters\ManyToOneAdapter
```

#### ArrayAdapter

[](#arrayadapter)

`IArrayAdapter` interface is implemented. Built-in adapters:

##### ManyToOneArrayAdapter

[](#manytoonearrayadapter)

All object relations are converted to an ID.

```
$entity = new Assoc class {
	public $id = 42;

	public $foo = 'foo';

	/**
	 * @ManyToOne(targetEntity="Assoc")
	 */
	public $assoc;
};

$entity->assoc->id++;

$array = $hydrator->toArray($entity);

$array === [
	'id' => 42,
	'assoc' => 43,
];
```

##### JoinArrayAdapter

[](#joinarrayadapter)

Object association is converted to an array.

```
$entity = new Assoc class {
	public $id = 42;

	public $foo = 'foo';

	/**
	 * @ManyToOne(targetEntity="Assoc")
	 */
	public $assoc;
};

$entity->assoc->id++;

$array = $hydrator->toArray($entity, [
	'joins' => [
		'assoc' => 'foo'
	]
]);

$array === [
	'id' => 42,
	'assoc' => 'foo',
];
```

#### FieldAdapter

[](#fieldadapter)

`IFieldAdapter` interface is implemented. Built-in adapters:

##### CallbackFieldAdapter

[](#callbackfieldadapter)

A callback can be used:

```
$hydrator->toFields($obj, [
	'name' => 'foo',
], [
	'callbacks' => [
		'name' => function (FieldArgs $args) {
		    $args->value = ucfirst($args->value);
		},
	]
]);
```

The value of the `$name` property is now `Foo`.

##### TargetEntityFieldAdapter

[](#targetentityfieldadapter)

In case of an association the corresponding entity will be found:

```
$hydrator->toFields($obj, [
	'assoc' => 42, // Item with the value of 42 will be found
]);
```

#### Creating a custom adapter

[](#creating-a-custom-adapter)

Say we have the following `image` custom type annotation:

```
/**
 * @ORM\Column(type="image")
 */
```

and we want to automatically save the image during hydration:

```
class CustomFieldAdapter implements IFieldAdapter {

	public function __construct(IImageStorage $storage) { ... }

	public function isWorkable(FieldArgs $args): bool {
		// Apply only when the type is `image` and it is not an assocation
		return !$args->metadata->isAssociation($field) && $args->metadata->getFieldMapping($field)['type'] === 'image';
	}

	public function work(FieldArgs $args): void {
		$image = new Image($value);
		if ($args->hasSettingsSection('images')) {
			$image->setName($args->getSettingsSection('images'));
		}
		$this->storage->save($image);

		$args->value = $image;
	}

}
```

Registration in Nette:

```
hydrator:
    adapters:
        fields:
            - CustomFieldAdapter
```

Usage:

```
$hydrator->toFields($obj, [
	'avatar' => __DIR__ . '/avatar.png',
], [
	'images' => [
		'avatar' => 'foo.png',
	]
]);
```

Development
-----------

[](#development)

This package was maintained by these authors.

[ ![](https://avatars2.githubusercontent.com/u/538058?v=3&s=80)](https://github.com/f3l1x)[ ![](https://avatars2.githubusercontent.com/u/749981?v=3&s=80)](https://github.com/Gappa)[ ![](https://avatars2.githubusercontent.com/u/10145362?v=3&s=80)](https://github.com/MartkCz)---

Consider to [support](https://contributte.org/partners.html) **contributte** development team. Also thank you for being used this package.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance50

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~49 days

Total

3

Last Release

2634d ago

PHP version history (2 changes)v1.0PHP &gt;= 7.1

v1.0.2PHP &gt;= 7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/312e788a47a251e05734378921d4596a91819b7de416fa18e77aa69e08798ea8?d=identicon)[Antik](/maintainers/Antik)

---

Top Contributors

[![petrparolek](https://avatars.githubusercontent.com/u/6066243?v=4)](https://github.com/petrparolek "petrparolek (5 commits)")[![f3l1x](https://avatars.githubusercontent.com/u/538058?v=4)](https://github.com/f3l1x "f3l1x (4 commits)")[![Gappa](https://avatars.githubusercontent.com/u/749981?v=4)](https://github.com/Gappa "Gappa (1 commits)")

---

Tags

arraycontributtedoctrineentityhydrationshydratornette-frameworknettrineobjectormphp

###  Code Quality

TestsCodeception

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/webchemistry-doctrine-hydration/health.svg)

```
[![Health](https://phpackages.com/badges/webchemistry-doctrine-hydration/health.svg)](https://phpackages.com/packages/webchemistry-doctrine-hydration)
```

###  Alternatives

[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M35](/packages/scienta-doctrine-json-functions)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[pixelfederation/doctrine-resettable-em-bundle

Symfony bundle for decorating default entity managers using a resettable decorator.

20113.5k](/packages/pixelfederation-doctrine-resettable-em-bundle)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1022.4k](/packages/rcsofttech-audit-trail-bundle)[ahmed-bhs/doctrine-doctor

Runtime analysis tool for Doctrine ORM integrated into Symfony Web Profiler. Unlike static linters, it analyzes actual query execution at runtime to detect performance bottlenecks, security vulnerabilities, and best practice violations during development with real execution context and data.

813.1k](/packages/ahmed-bhs-doctrine-doctor)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
