PHPackages                             lucatume/di52 - 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. [Framework](/categories/framework)
4. /
5. lucatume/di52

ActiveLibrary[Framework](/categories/framework)

lucatume/di52
=============

A PHP 5.6 compatible dependency injection container.

4.0.1(1y ago)721.5M↑73.4%128GPL-3.0PHPPHP &gt;=7.1CI passing

Since Nov 25Pushed 7mo ago5 watchersCompare

[ Source](https://github.com/lucatume/di52)[ Packagist](https://packagist.org/packages/lucatume/di52)[ RSS](/packages/lucatume-di52/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (63)Used By (8)

A PHP 5.6+ compatible dependency injection container inspired by [Laravel IOC](https://laravel.com/docs/5.0/container "Service Container - Laravel - The PHP Framework For Web Artisans")and [Pimple](http://pimple.sensiolabs.org/ "Pimple - A simple PHP Dependency Injection Container") that works even better on newer version of PHP.

A quick overview of the Container features:

- **Auto-wiring** - The Container will use Reflection to find what class should be built and how, it's *almost* magic.
- **Flexible** - Legacy code? Fat constructors with tons of side-effects? The Container offers auto-wiring without making it a requirement. It will adapt to existing code and will not require your code to adapt to it.
- **Fatal error handling** - On PHP 7.0+ the Container will take care of handling fatal errors that might happen at class file load time and handle them.
- **Fast** - The Container is optimized for speed as much as it can be squeezed out of the required PHP compatibility.
- **Flexible default mode** - Singleton (build at most once) an prototype (build new each time) default modes available.
- **Global Application** - Like using `App::get($service)->doStuff()`? The `App` facade allows using the DI Container as a globally available Service Locator.
- **PSR-11 compatible** - The container is fully compatible with [PSR-11 specification](https://www.php-fig.org/psr/psr-11/).
- **Ready for WordPress and other Event-driven frameworks** - The container API provides methods like [`callback`](#the-callback-method) and [`instance`](#the-instance-method) to easily be integrated with Event-driven frameworks like WordPress that require hooking callbacks to events.
- **Service Providers** - To keep your code organized, the library provides an [advanced Service Provider implementation](#service-providers).

Table of Contents
-----------------

[](#table-of-contents)

- [Code Example](#code-example)
- [Installation](#installation)
- [Upgrading from version 2 to version 3](#upgrading-from-version-2-to-version-3)
- [Upgrading from version 3.2 to version 3.3](#upgrading-from-version-32-to-version-33)
- [Quick and dirty introduction to dependency injection](#quick-and-dirty-introduction-to-dependency-injection)
    - [What is dependency injection?](#what-is-dependency-injection-)
    - [What is a DI container?](#what-is-a-di-container-)
    - [What is a Service Locator?](#what-is-a-service-locator-)
    - [Construction templates](#construction-templates)
- [The power of `get`](#the-power-of--get-)
- [Storing variables](#storing-variables)
- [Binding implementations](#binding-implementations)
- [Binding implementations to slugs](#binding-implementations-to-slugs)
- [Contextual binding](#contextual-binding)
- [Binding decorator chains](#binding-decorator-chains)
- [Tagging](#tagging)
- [The callback method](#the-callback-method)
- [Service providers](#service-providers)
    - [Booting service providers](#booting-service-providers)
    - [Deferred service providers](#deferred-service-providers)
    - [Dependency injection with service providers](#dependency-injection-with-service-providers)
- [Customizing the container](#customizing-the-container)
    - [Unbound classes resolution](#unbound-classes-resolution)
    - [Exception masking](#exception-masking)

Code Example
------------

[](#code-example)

In the application bootstrap file we define how the components will come together:

```
