PHPackages                             georgeff/container - 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. georgeff/container

ActiveLibrary[Framework](/categories/framework)

georgeff/container
==================

A light weight DI container

1.0.0(3mo ago)01521MITPHPPHP ^8.2CI passing

Since Feb 7Pushed 3mo agoCompare

[ Source](https://github.com/MikeGeorgeff/container)[ Packagist](https://packagist.org/packages/georgeff/container)[ RSS](/packages/georgeff-container/feed)WikiDiscussions main Synced 1mo ago

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

Container
=========

[](#container)

A lightweight dependency injection container implementing [PSR-11](https://www.php-fig.org/psr/psr-11/).

Installation
------------

[](#installation)

```
composer require georgeff/container
```

Usage
-----

[](#usage)

### Registering Definitions

[](#registering-definitions)

Register a definition by providing an ID and a callable factory. The container instance is passed to the factory.

```
use Georgeff\Container\Container;

$container = new Container();

$container->add('database', function (Container $container) {
    return new DatabaseConnection('localhost', 'mydb');
});
```

### Shared Definitions

[](#shared-definitions)

Shared definitions are resolved once and the same instance is returned on subsequent calls.

```
$container->addShared('database', function (Container $container) {
    return new DatabaseConnection('localhost', 'mydb');
});

// Or pass true as the third argument to add()
$container->add('database', function (Container $container) {
    return new DatabaseConnection('localhost', 'mydb');
}, true);
```

### Resolving Definitions

[](#resolving-definitions)

```
$db = $container->get('database');
```

### Aliases

[](#aliases)

Aliases allow you to resolve a definition by an alternate name, useful for binding interfaces to implementations.

```
$container->addShared(DatabaseConnection::class, function (Container $container) {
    return new DatabaseConnection('localhost', 'mydb');
});

$container->addAlias(DatabaseConnection::class, ConnectionInterface::class);

// Resolves the DatabaseConnection definition
$db = $container->get(ConnectionInterface::class);
```

### Checking for Definitions

[](#checking-for-definitions)

```
$container->has('database');    // true
$container->has('nonexistent'); // false
```

Exceptions
----------

[](#exceptions)

- `DefinitionNotFoundException` — thrown when getting a definition that does not exist or aliasing a non-existing definition. Implements PSR-11 `NotFoundExceptionInterface`.
- `CircularDependencyException` — thrown when a circular dependency is detected during resolution. Implements PSR-11 `ContainerExceptionInterface`.
- `ContainerException` — thrown when an error occurs during definition resolution. Implements PSR-11 `ContainerExceptionInterface`.

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance82

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

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

96d ago

### Community

Maintainers

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

---

Top Contributors

[![MikeGeorgeff](https://avatars.githubusercontent.com/u/6169468?v=4)](https://github.com/MikeGeorgeff "MikeGeorgeff (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/georgeff-container/health.svg)

```
[![Health](https://phpackages.com/badges/georgeff-container/health.svg)](https://phpackages.com/packages/georgeff-container)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[silverstripe/framework

The SilverStripe framework

7213.5M2.5k](/packages/silverstripe-framework)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6939.5M343](/packages/drupal-core-recommended)[cakephp/core

CakePHP Framework Core classes

6026.8M39](/packages/cakephp-core)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)

PHPackages © 2026

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