PHPackages                             php-di/zf2-bridge - 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. php-di/zf2-bridge

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

php-di/zf2-bridge
=================

Integrates PHP-DI to Zend Framework 2

1.0.20(7y ago)1118.4k14[1 issues](https://github.com/PHP-DI/ZF2-Bridge/issues)MITPHPPHP &gt;=5.5

Since Aug 3Pushed 7y ago3 watchersCompare

[ Source](https://github.com/PHP-DI/ZF2-Bridge)[ Packagist](https://packagist.org/packages/php-di/zf2-bridge)[ Docs](https://github.com/PHP-DI/ZF2-Bridge)[ RSS](/packages/php-di-zf2-bridge/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (25)Used By (0)

PHP-DI integration with Zend Framework 2
========================================

[](#php-di-integration-with-zend-framework-2)

[![Build Status](https://camo.githubusercontent.com/4213df061f11a4448c1a0e9107bb047863fce2e505273ead35f8c7997aca972b/68747470733a2f2f7472617669732d63692e6f72672f5048502d44492f5a46322d4272696467652e737667)](https://travis-ci.org/PHP-DI/ZF2-Bridge)

This library provides integration for PHP-DI with Zend Framework 2.

[PHP-DI](http://php-di.org/) is a Dependency Injection Container for PHP.

If you are looking for Zend Framework 1 integration, head over [here](https://github.com/php-di/PHP-DI-ZF1).

Use
---

[](#use)

Require the libraries with Composer:

```
{
    "require": {
        "php-di/php-di": "*",
        "php-di/zf2-bridge": "*"
    }
}
```

To use PHP-DI in your ZF2 application, you need to edit `application_root/config/application.config.php`:

```
    // ...
    'modules' => [
        ...
        'DI\ZendFramework2',
        ...
    ],

    'service_manager' => [
        // ...
        'factories' => [
            'DI\Container' => 'DI\ZendFramework2\Service\DIContainerFactory',
        ],
    ],
```

That's it!

Now you dependencies are injected in your controllers!

If you'd like to specify the di configuration yourself, create this file: `application_root/config/php-di.config.php`and save it with your PHP DI configuration e.g. like this:

```
return [
    'Application\Service\GreetingServiceInterface' => Di\object('Application\Service\GreetingService'),
];

```

Head over to [PHP-DI's documentation](http://php-di.org/doc/) if needed.

Fine tuning
-----------

[](#fine-tuning)

To configure the module, you have to override the module config somewhere at config/autoload/global.php or config/autoload/local.php.

```
return [
    'phpdi-zf2' => [
        ...
    ]
];
```

### Override definitions file location

[](#override-definitions-file-location)

```
return [
    'phpdi-zf2' => [
        'definitionsFile' => realpath(__DIR__ . '/../my.custom.def.config.php'),
    ]
];
```

### Enable or disable annotations

[](#enable-or-disable-annotations)

```
return [
    'phpdi-zf2' => [
        'useAnntotations' => true,
    ]
];
```

### Enable APCu

[](#enable-apcu)

```
return [
    'phpdi-zf2' => [
        'cache' => [
            'adapter' => 'apcu',
            'namespace' => 'your_di_cache_key',
        ],
    ]
];
```

### Enable file cache

[](#enable-file-cache)

```
return [
    'phpdi-zf2' => [
        'cache' => [
            'adapter' => 'filesystem',
            'namespace' => 'your_di_cache_key',
            'directory' => 'your_cache_directory', // default value is data/php-di/cache
        ],
    ]
];
```

### Enable redis cache

[](#enable-redis-cache)

If you are also using Redis for storing php sessions, it is very useful to configure the php-di cache handler to use a different database, since you might accidentally delete all your sessions when clearing the php-di definitions cache.

```
return [
    'phpdi-zf2' => [
        'cache' => [
            'namespace' => 'your_di_cache_key',
            'adapter' => 'redis',
            'host' => 'localhost', // default is localhost
            'port' => 6379, // default is 6379
            'database' => 1, // default is the same as phpredis default
        ],
    ]
];
```

### Enable Memcached cache

[](#enable-memcached-cache)

If you're using Memcached, you should have only one project per memcached instance.

```
return [
    'phpdi-zf2' => [
        'cache' => [
            'adapter' => 'memcached',
            'host' => 'localhost', // default is localhost
            'port' => 11211, // default is 11211
        ],
    ]
];
```

Console commands
----------------

[](#console-commands)

### Clear definition cache

[](#clear-definition-cache)

To clear the definition cache, run the following command from the project root:

```
php public/index.php php-di-clear-cache

```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 51.6% 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 ~84 days

Recently: every ~199 days

Total

24

Last Release

2735d ago

Major Versions

0.3.0 → 1.0.02015-05-24

PHP version history (3 changes)1.0.0PHP &gt;=5.3.3

1.0.1PHP &gt;=5.4

1.0.4PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/329a6111724074f5388e95dd41a03ccf3c43f4bfe1ecf27c94c9efc6f7823228?d=identicon)[mnapoli](/maintainers/mnapoli)

---

Top Contributors

[![Rastusik](https://avatars.githubusercontent.com/u/1735097?v=4)](https://github.com/Rastusik "Rastusik (32 commits)")[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (21 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (2 commits)")[![Mattin](https://avatars.githubusercontent.com/u/301784?v=4)](https://github.com/Mattin "Mattin (2 commits)")[![balihoo-jflitton](https://avatars.githubusercontent.com/u/5807460?v=4)](https://github.com/balihoo-jflitton "balihoo-jflitton (2 commits)")[![andrejvrabec](https://avatars.githubusercontent.com/u/12098306?v=4)](https://github.com/andrejvrabec "andrejvrabec (1 commits)")[![Ocramius](https://avatars.githubusercontent.com/u/154256?v=4)](https://github.com/Ocramius "Ocramius (1 commits)")[![bgaillard](https://avatars.githubusercontent.com/u/1327782?v=4)](https://github.com/bgaillard "bgaillard (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/php-di-zf2-bridge/health.svg)

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

###  Alternatives

[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

52664.9k12](/packages/solspace-craft-freeform)[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)[hostnet/entity-tracker-component

Provides an event when a Tracked entity changes

16158.1k4](/packages/hostnet-entity-tracker-component)[pdir/social-feed-bundle

Social feed extension for Contao CMS

1414.8k](/packages/pdir-social-feed-bundle)[antares/accessible

PHP library that allows you to define your class' getters, setters and constructor with docblock annotations.

123.9k1](/packages/antares-accessible)

PHPackages © 2026

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