PHPackages                             wuxi/hyperf-doctrine - 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. wuxi/hyperf-doctrine

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

wuxi/hyperf-doctrine
====================

This project provides an integration for the Doctrine ORM and the Hyperf framework.

08PHP

Since Mar 17Pushed 3y agoCompare

[ Source](https://github.com/wuxi889/hyperf-doctrine)[ Packagist](https://packagist.org/packages/wuxi/hyperf-doctrine)[ RSS](/packages/wuxi-hyperf-doctrine/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Hyperf 🤝 Doctrine
=================

[](#hyperf--doctrine)

This project provides an integration for the Doctrine ORM and the Hyperf framework.

[![CI](https://github.com/leocavalcante/hyperf-doctrine/actions/workflows/ci.yml/badge.svg)](https://github.com/leocavalcante/hyperf-doctrine/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/f31ebe213656616aa1c1b3bb7343d485a9d0cfae78e1a742f893530c38e8090c/68747470733a2f2f636f6465636f762e696f2f67682f6c656f636176616c63616e74652f6879706572662d646f637472696e652f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d59644b37705166634f51)](https://codecov.io/gh/leocavalcante/hyperf-doctrine)[![PHPStan](https://camo.githubusercontent.com/83dd3d35cebed0eab9ee97ff1a5849c1344cda6a8ee9cac2cda20f5aa55b67bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d627269676874677265656e2e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/83dd3d35cebed0eab9ee97ff1a5849c1344cda6a8ee9cac2cda20f5aa55b67bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d627269676874677265656e2e7376673f7374796c653d666c6174)

Install
-------

[](#install)

```
composer require leocavalcante/hyperf-doctrine

```

Setup
-----

[](#setup)

You should publish `hyperf/db` as this package uses it as the underlaying driver engine:

```
php bin/hyperf.php vendor:publish hyperf/db
```

**⭐ This means that you have Doctrine ORM baked into Hyperf pools and connections lifecycle management free of charge** - *How awesome?*

Configure the database in `config/autoload/db.php`:

```
return [
    'default' => [
        'driver' => 'pdo',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', 3306),
        'database' => env('DB_DATABASE', 'hyperf'),
        'username' => env('DB_USERNAME', 'root'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => env('DB_CHARSET', 'utf8mb4'),
        'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
        'fetch_mode' => PDO::FETCH_ASSOC,
        'pool' => [
            'min_connections' => 1,
            'max_connections' => 10,
            'connect_timeout' => 10.0,
            'wait_timeout' => 3.0,
            'heartbeat' => -1,
            'max_idle_time' => (float) env('DB_MAX_IDLE_TIME', 60),
        ],
        'options' => [
            PDO::ATTR_CASE => PDO::CASE_NATURAL,
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
            PDO::ATTR_STRINGIFY_FETCHES => false,
            PDO::ATTR_EMULATE_PREPARES => false,
        ],
    ],
];
```

Then publish Hyperf Doctrine configurations:

```
php bin/hyperf.php vendor:publish leocavalcante/hyperf-doctrine
```

You can edit Doctrine's Entity Manager settings in `config/autoload/doctrine.php`:

```
return [
    'connection' => [
        'driverClass' => Hyperf\Doctrine\Driver::class,
        'pool' => 'default',
    ],
    'config' => Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration([__DIR__ . '/app']),
];
```

It will also publish a `cli-config.php` to `config/` so you can already run `vendor/bin/doctrine`, for example:

```
vendor/bin/doctrine orm:schema-tool:create
```

Usage
-----

[](#usage)

At this time, you are ready to use Doctrine ORM with Hyperf.

For example, create an Entity as you would do regulary:

```
/**
 * @ORM\Entity()
 * @ORM\Table(name="users")
 */
final class User
{
    public function __construct(
        /**
         * @ORM\Id()
         * @ORM\Column(type="integer")
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        public int $id,
        /*
         * @ORM\Column(type="string")
         */
        public string $name,
        /**
         * @ORM\Column(type="string")
         */
        public string $email,
    ) {
    }
}
```

Then let dependency injection magic do the work to inject an `EntityManager` into your application:

```
/**
 * @Controller(prefix="users")
 */
final class UsersController
{
    public function __construct(
        private EntityManagerInterface $em,
    ) {
    }

    /**
     * @GetMapping(path="")
     */
    public function index(RequestInterface $request, ResponseInterface $response)
    {
        return $this->em->getRepository(User::class)->findAll();
    }
}
```

**And that is it!**

Feel free to contribute submiting issues and PRs.

---

MIT © 2022 Leo Cavalcante

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 Bus Factor1

Top contributor holds 85.7% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a135d1430f470f4a1eaf3eb1787283a8d862feee5dbdbe8ab0ab8617e0bc7d4b?d=identicon)[usee](/maintainers/usee)

---

Top Contributors

[![leocavalcante](https://avatars.githubusercontent.com/u/183722?v=4)](https://github.com/leocavalcante "leocavalcante (12 commits)")[![wuxi889](https://avatars.githubusercontent.com/u/29323350?v=4)](https://github.com/wuxi889 "wuxi889 (2 commits)")

### Embed Badge

![Health badge](/badges/wuxi-hyperf-doctrine/health.svg)

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M542](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M209](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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