PHPackages                             mrclay/props-dic - 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. mrclay/props-dic

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

mrclay/props-dic
================

Props is a simple DI container that allows retrieving values via custom property and method names

4.0.0(2y ago)3611.7M—0.7%9[2 PRs](https://github.com/mrclay/Props/pulls)3MITPHPPHP &gt;=8.1.0CI failing

Since Jan 7Pushed 2y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (3)Versions (9)Used By (3)

Props [![Build Status](https://github.com/mrclay/Props/actions/workflows/php.yml/badge.svg)](https://github.com/mrclay/Props/actions)
=====================================================================================================================================

[](#props-)

Most [Dependency Injection](http://www.mrclay.org/2014/04/06/dependency-injection-ask-for-what-you-need/) containers have fetch operations, like `$di->get('foo')` or `$di['foo']`, which don't allow your IDE to know the type of value received, nor offer you any help remembering/typing key names.

With **Props**, you access values via custom property reads `$di->foo` or method calls `$di->new_foo()`. This allows you to subclass the container and provide `@property` and/or `@method` PHPDoc declarations, giving your IDE and static analysis tools valuable runtime type information.

An example will help:

```
/**
 * @property-read Foo $foo
 * @method        Foo new_foo()
 */
class MyContainer extends \Props\Container {
    public function __construct() {
        $this->foo = function (MyContainer $c) {
            return new Foo();
        };
    }
}

$c = new MyContainer();

$foo1 = $c->foo; // your IDE knows this is a Foo instance

$foo2 = $c->new_foo(); // A fresh Foo instance

$foo3 = $c->foo; // same as $foo1
```

Here's a more complex example:

```
/**
 * @property-read string $style
 * @property-read Dough  $dough
 * @property-read Cheese $cheese
 * @property-read Pizza  $pizza
 * @method        Slice  new_slice()
 */
class PizzaServices extends \Props\Container {
    public function __construct() {
        $this->style = 'deluxe';

        $this->dough = function (PizzaServices $c) {
            return new Dough();
        };

        $this->setFactory('cheese', 'CheeseFactory::getCheese');

        $this->pizza = function (PizzaServices $c) {
            $pizza = new Pizza($c->style, $c->cheese);
            $pizza->setDough($c->dough);
            return $pizza;
        };

        $this->slice = function (PizzaServices $c) {
            return $c->pizza->getSlice();
        };
    }
}

$c = new PizzaServices;

$c->pizza; // This first resolves and caches the cheese and dough.

$c->pizza; // The same pizza instance as above (no factories called).
```

Since "slice" has a factory function set, we can call `new_slice()` to get fresh instances from it:

```
$c->new_slice(); // a new Slice instance
$c->new_slice(); // a new Slice instance
```

Your IDE sees the container as a plain old class of typed properties, allowing it to offer suggestions of available properties, autocomplete their names, and autocomplete the objects returned. It gives you much more power when providing static analysis and automated refactoring.

Compatibility
-------------

[](#compatibility)

`Props\Container` implements [`ContainerInterface`](https://github.com/php-fig/container/blob/master/src/ContainerInterface.php).

Overview
--------

[](#overview)

You can specify dependencies via direct setting:

```
$c->aaa = new AAA();
```

You can specify factories by setting a `Closure`, or by using the `setFactory()` method. These are functionally equivalent:

```
$c->bbb = function ($c) {
    return BBB::factory($c);
};

$c->setFactory('bbb', 'BBB::factory');
```

Resolved dependencies are cached, returning the same instance:

```
$c->bbb === $c->bbb; // true
```

### Using factories

[](#using-factories)

If you don't want a cached value, use `new_PROPERTYNAME()` to always fetch a fresh instance:

```
$c->new_bbb() === $c->new_bbb(); // false
```

Regular value sets do not store a factory, so you may want to check `hasFactory()` before you use `new_PROPERTYNAME()`:

```
// store a value
$c->ccc = new CCC();
$c->hasFactory('ccc'); // false

// store a factory
$c->ccc = function () {
    return new CCC();
};
$c->hasFactory('ccc'); // true
```

You can also get access to a set factory:

```
$callable = $c->getFactory('ccc');
```

### Extending a factory

[](#extending-a-factory)

Use `extend` to have the return value of a factory filtered before it's returned:

```
$c->foo = function ($c) {
    return new Foo($c->bar);
};

$c->extend('foo', function ($value, Container $c) {
    return array($value, $c->bing);
});

$c->foo; // [Foo, "bing"]

$c->new_foo(); // re-call original foo factory and re-extend output (`bar` and `bing` will be re-read)
```

Pimple with property access
---------------------------

[](#pimple-with-property-access)

If you're used to the [Pimple](http://pimple.sensiolabs.org/) API, try `Props\Pimple`, which just adds property access. With that you can add `@property` declarations and get the same typing benefits.

You can see an [example](https://github.com/mrclay/Props/blob/master/scripts/example-pimple.php) that's similar to the Pimple docs.

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

[](#requirements)

- PHP 8.1

### License (MIT)

[](#license-mit)

See [LICENSE](https://github.com/mrclay/Props/blob/master/src/LICENSE).

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity58

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 81.6% 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 ~469 days

Recently: every ~721 days

Total

8

Last Release

866d ago

Major Versions

1.0.0 → 2.0.02016-01-21

2.2.0 → 3.0.02019-11-26

3.0.1 → 4.0.02024-01-04

PHP version history (2 changes)1.0.0PHP &gt;=5.3.3

4.0.0PHP &gt;=8.1.0

### Community

Maintainers

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

---

Top Contributors

[![mrclay](https://avatars.githubusercontent.com/u/170687?v=4)](https://github.com/mrclay "mrclay (40 commits)")[![glensc](https://avatars.githubusercontent.com/u/199095?v=4)](https://github.com/glensc "glensc (4 commits)")[![androidacy-user](https://avatars.githubusercontent.com/u/45006100?v=4)](https://github.com/androidacy-user "androidacy-user (2 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (2 commits)")[![brandonkelly](https://avatars.githubusercontent.com/u/47792?v=4)](https://github.com/brandonkelly "brandonkelly (1 commits)")

---

Tags

containerdi containerdependency-injectiondidependency injection container

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mrclay-props-dic/health.svg)

```
[![Health](https://phpackages.com/badges/mrclay-props-dic/health.svg)](https://phpackages.com/packages/mrclay-props-dic)
```

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[aura/di

A serializable dependency injection container with constructor and setter injection, interface and trait awareness, configuration inheritance, and much more.

356968.3k58](/packages/aura-di)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2857.5k2](/packages/capsule-di)

PHPackages © 2026

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