PHPackages                             karolak/psr-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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. karolak/psr-container

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

karolak/psr-container
=====================

PSR-11 container implementation.

01PHP

Since Feb 27Pushed 2mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

karolak/psr-container
=====================

[](#karolakpsr-container)

A minimal, zero-dependency PSR-11 container implementation for PHP.

All services are resolved lazily on first access and reused on subsequent calls.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.4
- [psr/container](https://packagist.org/packages/psr/container) ^2.0

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

[](#installation)

```
composer require karolak/psr-container
```

Usage
-----

[](#usage)

```
use Karolak\PsrContainer\Container;

$container = new Container([
    LoggerInterface::class => static fn (): FileLogger => new FileLogger('/var/log/app.log'),
    Connection::class      => static fn (): Connection => new Connection('sqlite::memory:'),
    UserRepository::class  => static function (Container $c): UserRepository {
        return new UserRepository(
            $c->get(Connection::class),
            $c->get(LoggerInterface::class),
        );
    },
]);

$repository = $container->get(UserRepository::class);
```

Each factory receives the container instance as its only argument, so you can resolve other services as dependencies. Every factory is called at most once — subsequent calls to `get()` return the cached instance.

OPcache optimization
--------------------

[](#opcache-optimization)

For best performance, define your container factories in a dedicated PHP file. This allows OPcache to compile and cache the file, avoiding repeated parsing on every request.

```
// config/services.php
return [
    LoggerInterface::class => static fn (): FileLogger => new FileLogger('/var/log/app.log'),
    Connection::class      => static fn (): Connection => new Connection('sqlite::memory:'),
];
```

```
// public/index.php
$container = new Container(require __DIR__ . '/../config/services.php');
```

License
-------

[](#license)

MIT

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance56

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2c3da892874c330d8ee681c08f4ada3c22157bb9c3ac90623cc9356fdace4f00?d=identicon)[karolak](/maintainers/karolak)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[league/container

A fast and intuitive dependency injection container.

86787.8M343](/packages/league-container)[stella-maris/clock

A pre-release of the proposed PSR-20 Clock-Interface

7947.5M2](/packages/stella-maris-clock)[wptrt/wpthemereview

PHP\_CodeSniffer rules (sniffs) to verify theme compliance with the rules for theme hosting on wordpress.org

217736.5k29](/packages/wptrt-wpthemereview)[inpsyde/modularity

Modular PSR-11 implementation for WordPress plugins, themes or libraries.

54383.3k3](/packages/inpsyde-modularity)[php-standard-library/phpstan-extension

PHPStan PSL extension

201.2M13](/packages/php-standard-library-phpstan-extension)[elie29/zend-phpdi-config

PSR-11 PHP-DI autowire container configurator for Laminas, Mezzio, ZF2, ZF3 and Zend Expressive applications

20238.6k7](/packages/elie29-zend-phpdi-config)

PHPackages © 2026

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