PHPackages                             pmjones/caplet - 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. pmjones/caplet

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

pmjones/caplet
==============

A minimal PSR-11 compliant autowiring dependency injection container.

1.0.0(3y ago)8211MITPHPPHP ^8.0

Since Apr 19Pushed 3y ago3 watchersCompare

[ Source](https://github.com/pmjones/caplet)[ Packagist](https://packagist.org/packages/pmjones/caplet)[ RSS](/packages/pmjones-caplet/feed)WikiDiscussions 1.x Synced today

READMEChangelog (1)Dependencies (5)Versions (2)Used By (1)

Caplet
======

[](#caplet)

*Caplet* is a minimal autowiring dependency injection container to handle basic constructor injection and object factories.

Getting Started
---------------

[](#getting-started)

Instantiate *Caplet* like so:

```
use Caplet\Caplet;

$caplet = new Caplet();
```

You can then call one of these PSR-11 methods:

- `get(string $class) : object` to get a shared object instance of `$class`.
- `has(string $class) : bool` to see if an instance is available. (This means either a class definition exists; or, in the case of an interface, the interface definition exists *and* has a `factory()` entry -- see below for the `factory()` method.)

*Caplet* offers this non-PSR-11 method:

- `new(string $class) : object` to get a new object instance of `$class`. (This method is *not* part of PSR-11.)

Configuration
-------------

[](#configuration)

Configure non-object constructor arguments by passing an array with the structure `$config['ClassName']['parameterName']` at *Caplet* construction time. For example, given the following class ...

```
namespace Foo;

class Bar
{
    public function __construct(
        protected string $bar,
        protected string $baz
    ) {
    }
}
```

... you would configure the arguments for its parameters like so:

```
use Caplet\Caplet;
use Foo\Bar;

$caplet = new Caplet([
    Bar::class => [
        'bar' => 'bar-value',
        'baz' => 'baz-value',
    ];
]);

$bar = $caplet->get(Bar::class);
```

Alternatively, extend *Caplet* and override `__construct()` to accept your own environment or configuration values, then call the `parent::__construct()` with the `$config['ClassName']['parameterName']` structure.

```
namespace Project;

use Caplet\Caplet;

class ProjectCaplet extends Caplet
{
    public function __construct(array $env)
    {
        parent::__construct([
            Foo::class => [
                'bar' => $env['BAR_VALUE'],
                'baz' => $env['BAZ_VALUE'],
            ],
        ]);
    }
}
```

Factories
---------

[](#factories)

Extending *Caplet* also allows you to call the protected `factory()` method inside the constructor to define the object-creation logic for a given type. This allows you to specify concrete classes for instantiation in place of abstracts or interfaces. For example:

```
namespace Project;

use Caplet\Caplet;
use Project\Log\Logger;
use Psr\Log\LoggerInterface;

class ProjectCaplet extends Caplet
{
    public function __construct(
        string $bar,
        string $baz,
    ) {
        parent::__construct([
            Foo::class => [
                'bar' => 'bar-value',
                'baz' => 'baz-value',
            ],
        ]);

        $this->factory(
            LoggerInterface::class,
            fn (Caplet $caplet) => $caplet->get(Logger::class)
        );
    }
}
```

As seen above, the callable factory logic must have the signature `function (Caplet $caplet)`, and may specify a return type.

Constructor Parameter Resolution
--------------------------------

[](#constructor-parameter-resolution)

*Caplet* will attempt to resolve constructor parameters in this order:

- First, use an argument from $config, if one is available.
- Next, try to `get()` an object of the parameter type.
- Last, use the default parameter value, if one is defined.

If none of these work, *Caplet* will throw *Exception\\NotInstantiated*, with a previous exception of *Exception\\NotResolved*.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

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

Every ~39 days

Total

2

Last Release

1130d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25754?v=4)[Paul M. Jones](/maintainers/pmjones)[@pmjones](https://github.com/pmjones)

---

Top Contributors

[![pmjones](https://avatars.githubusercontent.com/u/25754?v=4)](https://github.com/pmjones "pmjones (6 commits)")

---

Tags

containerdependencyinjectiondependency-injectiondiiocinversion of control

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pmjones-caplet/health.svg)

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

###  Alternatives

[league/container

A fast and intuitive dependency injection container.

86894.4M437](/packages/league-container)[php-di/php-di

The dependency injection container for humans

2.9k55.5M1.2k](/packages/php-di-php-di)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2860.1k2](/packages/capsule-di)[slince/di

A flexible dependency injection container

20272.1k6](/packages/slince-di)[miladrahimi/phpcontainer

Dependency injection (IoC) container for PHP projects

1324.1k2](/packages/miladrahimi-phpcontainer)

PHPackages © 2026

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