PHPackages                             kbondurant/self-provider-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. kbondurant/self-provider-container

ActiveLibrary

kbondurant/self-provider-container
==================================

Declare your definitions from within your service itself

1.0.1(4y ago)017.6k↓37.8%[1 PRs](https://github.com/kbondurant/self-provider-container/pulls)MITPHPPHP ^8.0 || ^8.1

Since Feb 27Pushed 1y ago1 watchersCompare

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

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

Self Provider Container
=======================

[](#self-provider-container)

A delegate container for [league/container](https://container.thephpleague.com/).

Declare your definitions directly from your service just before you retrieve it for the first time

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

[](#installation)

Via Composer

```
composer require kbondurant/self-provider-container
```

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

[](#requirements)

The following versions of PHP are supported by this version.

- PHP 8.0
- PHP 8.1

Usage
-----

[](#usage)

You should add the SelfProviderContainer before the ReflectionContainer if you use it too.

```
use Kbondurant\SelfProviderContainer\SelfProviderContainer;
use League\Container\Container;
use League\Container\ReflectionContainer;

$container = new Container();

$container->delegate(new SelfProviderContainer());
$container->delegate(new ReflectionContainer());
```

Now you can implement the ServiceProvider interface (or any interface that extends it) and add your definitions in the register method. When you will try to retrieve your LeagueRouter from the container for the first time it will first call the register method before even trying to instantiate it.

```
class LeagueRouter implements ServiceProvider
{
    public function __construct(
        private Router $router,
    ) {
    }

    /**
     * @param \League\Container\DefinitionContainerInterface $container
     * @return void
     */
    public static function register(mixed $container): void
    {
        $container->add(Router::class, fn () => new Router())
            ->setShared(true);
    }
}
```

By default, an instance of League\\Container\\DefinitionContainerInterface will be passed to the register::method, but you have the possibility to change that by passing your own container instance to the SelfProviderContainer

```
use Acme\Container\MyOwnContainer;
use Kbondurant\SelfProviderContainer\SelfProviderContainer;
use League\Container\Container;
use League\Container\ReflectionContainer;

$container = new Container();

$container->delegate(new SelfProviderContainer(new MyOwnContainer()));
$container->delegate(new ReflectionContainer());
```

An instance of Acme\\Container\\MyOwnContainer will now be passed to the register method

```
class LeagueRouter implements ServiceProvider
{
    public function __construct(
        private Router $router,
    ) {
    }

    /**
     * @param \Acme\Container\MyOwnContainer $container
     * @return void
     */
    public static function register(mixed $container): void
    {
        $container->singleton(Router::class, fn () => new Router());
    }
}
```

Limitations
-----------

[](#limitations)

#### You should use this pattern only if the service(s) that you are about to register is injected in one class only (adapters, etc...), otherwise you might redeclare the same service many times which might give you slow performances or even bugs with shared definitions

[](#you-should-use-this-pattern-only-if-the-services-that-you-are-about-to-register-is-injected-in-one-class-only-adapters-etc-otherwise-you-might-redeclare-the-same-service-many-times-which-might-give-you-slow-performances-or-even-bugs-with-shared-definitions)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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

Every ~1 days

Total

2

Last Release

1540d ago

### Community

Maintainers

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

---

Top Contributors

[![kbondurant](https://avatars.githubusercontent.com/u/14251523?v=4)](https://github.com/kbondurant "kbondurant (3 commits)")

---

Tags

php

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/kbondurant-self-provider-container/health.svg)

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

###  Alternatives

[cakephp/cakephp

The CakePHP framework

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

CakePHP Framework Core classes

6126.8M39](/packages/cakephp-core)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)[api-platform/state

API Platform state interfaces

223.4M57](/packages/api-platform-state)[neos/flow-development-collection

Flow packages in a joined repository for pull requests.

144179.3k3](/packages/neos-flow-development-collection)

PHPackages © 2026

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