PHPackages                             zorac/php-di-migration - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. zorac/php-di-migration

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

zorac/php-di-migration
======================

Eases migration from PHP-DI 6 annotations to PHP-DI 7 attributes

1.0.0(3y ago)0400MITPHPPHP &gt;=8.0

Since Apr 20Pushed 3y ago1 watchersCompare

[ Source](https://github.com/zorac/php-di-migration)[ Packagist](https://packagist.org/packages/zorac/php-di-migration)[ Docs](https://github.com/zorac/php-di-migration)[ RSS](/packages/zorac-php-di-migration/feed)WikiDiscussions main Synced 1mo ago

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

PHP-DI Migration
================

[](#php-di-migration)

[![Software license](https://camo.githubusercontent.com/d4d7ba62db47a5c14ede3ab87c4881c50a3645c86723b76f443c82da511a22fc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7a6f7261632f7068702d64692d6d6967726174696f6e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![PHP version](https://camo.githubusercontent.com/93295106909eb50c079ecd8a939fb5c7c73fc902a02e1cd0480803136b3726df/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7a6f7261632f7068702d64692d6d6967726174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://www.php.net/)[![Latest release](https://camo.githubusercontent.com/167f488699550e8c574c683e7671d27bd732335d63042740855feab3418dcf2c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a6f7261632f7068702d64692d6d6967726174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zorac/php-di-migration)

Eases migration from PHP-DI 6 annotations to PHP-DI 7 attributes.

Rationale
---------

[](#rationale)

PHP-DI 7 replaces the usage of PHPDoc `@Inject` and `@Injectable` annotations with native PHP 8 `#[Inject]` and `#[Injectable]` attributes. This is very much a change for the better, but all of your code needs to be updated at once, which can be difficult or dangerous across a large codebase with multiple contributors. This project provides a smoother migration path by supporting attributes alongside annotations while you migrate your code.

Warning
-------

[](#warning)

This code has not been extensively tested for all use cases and edge cases. Use at your own risk!

Usage
-----

[](#usage)

Install the migration package alongside PHP-DI 6:

```
composer require zorac/php-di-migration
```

Replace `ContainerBuilder` with `MigrationContainerBuilder` and enable annotations:

```
// Before:
$builder = new DI\ContainerBuilder();
$builder->useAnnotations(true);
// etc...
$container = $builder->build();

// After:
$builder = new DI\MigrationContainerBuilder();
$builder->useAnnotations(true);
$builder->useAttributes(true);
// etc...
$container = $builder->build();
```

Commit and merge the changes, and you're ready to start migrating!

Over time, migrate your code from attributes to annotations, remembering to add strong PHP types anywhere you're currently relying on PHPDoc typing, and to remove any imports of `DI\Annotation\Inject` etc.

Once your code is all migrated, remove the `useAnnotations(false)` call from the container builder for final testing. If you missed any typing changes, this is when things will break.

Once you're happy with your fully migrated code, you can remove `zorac/php-di-migration` and upgrade to PHP-DI 7, switching back to using `DI\ContainerBuilder`. You may also be able to remove `doctrine/annotations` if you're not relying on it for anything else.

Congratulations! Your PHP-DI migration is complete.

Implementation Notes
--------------------

[](#implementation-notes)

- `MigrationContainerBuilder` is a modified version of PHP-DI 6's `ContainerBuilder` with changes ported from PHP-DI 7's version to add support for `useAttributes`, and additional changes to support annotations and attributes in parallel.
- `AttributeAndAnnotationBasedAutowiring` is a modified version of PHP-DI 6's `AnnotationBasedAutowiring` with changes ported from PHP-DI 7's `AttributeBasedAutowiring` to support annotations and attributes in parallel.
- All other classes are copied verbatim from PHP-DI 7.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

1124d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2768ebe682a76e86ee591ffccbf100c4f2927c61bce46a955cbf7444585ededa?d=identicon)[zorac](/maintainers/zorac)

---

Top Contributors

[![zorac](https://avatars.githubusercontent.com/u/1845517?v=4)](https://github.com/zorac "zorac (6 commits)")

---

Tags

phpphp-di

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/zorac-php-di-migration/health.svg)

```
[![Health](https://phpackages.com/badges/zorac-php-di-migration/health.svg)](https://phpackages.com/packages/zorac-php-di-migration)
```

###  Alternatives

[infinum/eightshift-libs

WordPress libs developed by Eightshift team to use in modern WordPress.

63118.9k3](/packages/infinum-eightshift-libs)[drupal-code-builder/drupal-code-builder

Code generator for Drupal

27241.1k1](/packages/drupal-code-builder-drupal-code-builder)[php-di/zf1-bridge

Integrates PHP-DI to Zend Framework 1

27457.8k1](/packages/php-di-zf1-bridge)[sansec/composer-integrity-plugin

5624.2k1](/packages/sansec-composer-integrity-plugin)[php-di/symfony-bridge

Integrates PHP-DI to Symfony

17168.2k](/packages/php-di-symfony-bridge)[okapi/aop

PHP AOP is a PHP library that provides a powerful Aspect Oriented Programming (AOP) implementation for PHP.

3812.0k](/packages/okapi-aop)

PHPackages © 2026

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