PHPackages                             jonsa/pimple-ioc - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jonsa/pimple-ioc

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jonsa/pimple-ioc
================

Resolve classes out of a Pimple container

v1.3.0(10y ago)1661MITPHP

Since Sep 27Pushed 10y ago1 watchersCompare

[ Source](https://github.com/jonsa/pimple-ioc)[ Packagist](https://packagist.org/packages/jonsa/pimple-ioc)[ RSS](/packages/jonsa-pimple-ioc/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (3)Versions (6)Used By (1)

Pimple IoC
==========

[](#pimple-ioc)

Class resolver for the [Pimple](http://pimple.sensiolabs.org/) container.

This project is heavily inspired by how [Laravel](http://laravel.com/) resolve it's classes out of their IoC container. In fact most of the code is taken directly from their `Container` class.

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

[](#installation)

Add the IoC container to your `composer.json` using the command line.

```
composer require jonsa/pimple-ioc

```

Usage
-----

[](#usage)

The class resolver is registered in Pimple as a `ServiceProvider`

```
use Jonsa\PimpleResolver\ServiceProvider;
use Pimple\Container;

$container = new Container();
$container->register(new ServiceProvider());
```

This will register the `make` key on the Container which resolves the requested class.

```
$instance = $container['make']('Acme\MyClass');
```

and the `bind` key to bind a definition to a concrete implementation

```
$container['bind']('Acme\MyInterface', 'Acme\MyClass');
```

### Resolved recursively

[](#resolved-recursively)

Class dependencies are resolved recursively.

```
interface FooContract {}

class Foo implements FooContract {};

class Bar {
    public function __construct(FooContract $foo) {}
}

class Baz {
    public function __construct(Bar $bar) {}
}

$container['bind']('FooContract', 'FooClass');
$baz = $container['make']('Baz');
```

### Define constructor parameters

[](#define-constructor-parameters)

To override a class parameter use the parameter array on the resolver method.

```
class Log {
    public function __construct(Psr\Log\LoggerInterface $logger, $level = Psr\Log\LogLevel::WARNING)
    {
        ...
    }
}

$container['make']('Log', array(
    'level' => Psr\Log\LogLevel::DEBUG
));
```

### Inject into the resolver workflow

[](#inject-into-the-resolver-workflow)

To customize a resolved class before it is returned from the resolver, simply listen to the `CLASS_RESOLVED` event.

```
use Jonsa\PimpleResolver\ServiceProvider;
use Jonsa\PimpleResolver\Events;
use Symfony\Component\EventDispatcher\EventDispatcher;

$dispatcher = new EventDispatcher;
$container[ServiceProvider::EVENT_DISPATCHER] = function () use ($dispatcher) {
    return $dispatcher;
});

$dispatcher->addListener(Events::CLASS_RESOLVED, function (ClassResolvedEvent $event) {
    $object = $event->getResolvedObject();
    ...
});
```

Alternatively the `EVENT_DISPATCHER` key can be populated with a string which in turn returns an event dispatcher from the container

```
$container[ServiceProvider::EVENT_DISPATCHER] = 'my dispatcher key';
```

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

[](#configuration)

The ServiceProvider has three configuration parameters.

```
class ServiceProvider implements ServiceProviderInterface {
    public function __construct($bindContainerInstance = true, $makeMethod = 'make', $bindMethod = 'bind')
    {
        ...
    }
}
```

`$bindContainerInstance` tells the ServiceProvider whether to bind the container instance to the `'Pimple\Container'` key. If the container is extended, that class name will also be bound to the container instance.

`$makeMethod` is used to define which key on the container to be used as the make method.

`$bindMethod` is used to define which key on the container to be used as the bind method.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

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 ~2 days

Total

5

Last Release

3913d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/84fefa5af43cddaa8ffa30a7474e9a4dc1f57e269390759e9386878d6b3fa979?d=identicon)[jonsa](/maintainers/jonsa)

---

Top Contributors

[![jonsa](https://avatars.githubusercontent.com/u/807381?v=4)](https://github.com/jonsa "jonsa (2 commits)")

---

Tags

iocpimple

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jonsa-pimple-ioc/health.svg)

```
[![Health](https://phpackages.com/badges/jonsa-pimple-ioc/health.svg)](https://phpackages.com/packages/jonsa-pimple-ioc)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[phpro/soap-client

A general purpose SoapClient library

8895.9M52](/packages/phpro-soap-client)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

749284.3k35](/packages/civicrm-civicrm-core)[oat-sa/tao-core

TAO core extension

66140.1k108](/packages/oat-sa-tao-core)[rochamarcelo/cake-pimple-di

A cakephp plugin for dependency injection based on Pimple library

12180.8k](/packages/rochamarcelo-cake-pimple-di)

PHPackages © 2026

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