PHPackages                             mnapoli/simplex - 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. mnapoli/simplex

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

mnapoli/simplex
===============

Pimple fork with full container-interop support

0.5.0(8y ago)13124.3k516MITPHPPHP &gt;=5.3.0

Since Feb 25Pushed 8y ago3 watchersCompare

[ Source](https://github.com/mnapoli/simplex)[ Packagist](https://packagist.org/packages/mnapoli/simplex)[ Docs](https://github.com/mnapoli/simplex)[ RSS](/packages/mnapoli-simplex/feed)WikiDiscussions master Synced today

READMEChangelog (7)Dependencies (3)Versions (8)Used By (16)

[![Build Status](https://camo.githubusercontent.com/d00f8bddeb5c3f06509f1c16ab2fe1c9332044445d9b98712e8647170399c948/68747470733a2f2f7472617669732d63692e6f72672f6d6e61706f6c692f73696d706c65782e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mnapoli/simplex)

Simplex
=======

[](#simplex)

Simplex is a [Pimple 3](https://github.com/silexphp/Pimple) fork with full [PSR-11](https://www.php-fig.org/psr/psr-11/) compliance and [cross-framework service-provider](https://github.com/container-interop/service-provider) support.

Simplex is a small dependency injection container for PHP.

Differences with Pimple
-----------------------

[](#differences-with-pimple)

Simplex is a fork of Pimple's code. The only differences are the following:

- `Simplex\Container` implements [`ContainerInterface`](https://github.com/container-interop/container-interop/blob/master/src/Interop/Container/ContainerInterface.php), which means the following methods exist:
    - `$container->get($id)` which is an alias to `$container[$id]`
    - `$container->has($id)` which is an alias to `isset($container[$id])`
- for symmetry reasons, `Simplex\Container` also provides an additional method:
    - `$container->set($id, $value)` which is an alias to `$container[$id] = ...`
- the constructor takes an optional `ContainerInterface $rootContainer = null` argument to support the [delegate lookup feature](https://github.com/container-interop/container-interop/blob/master/docs/Delegate-lookup.md): if provided, this container will be injected in factories instead
- service providers have been completely replaced by [container-interop's service providers](https://github.com/container-interop/service-provider): that allows to load cross-framework modules in this container
- it is possible to extend a scalar value with `$container->extend()` (for compatibility reasons with cross-framework service providers)

Below is the documentation of Pimple/Simplex.

Installation
============

[](#installation)

```
composer require mnapoli/simplex

```

Usage
=====

[](#usage)

Creating a container is a matter of creating a `Container` instance:

```
$container = new \Simplex\Container();
```

Defining Services
-----------------

[](#defining-services)

A service is an object that does something as part of a larger system. Examples of services: a database connection, a templating engine, or a mailer. Almost any **global** object can be a service.

Services are defined by **anonymous functions** that return an instance of an object:

```
// define some services
$container['session_storage'] = function ($c) {
    return new SessionStorage('SESSION_ID');
};

$container['session'] = function ($c) {
    return new Session($c['session_storage']);
};
```

Notice that the anonymous function has access to the current container instance, allowing references to other services or parameters.

As objects are only created when you get them, the order of the definitions does not matter.

Using the defined services is also very easy:

```
// get the session object
$session = $container['session'];

// the above call is roughly equivalent to the following code:
// $storage = new SessionStorage('SESSION_ID');
// $session = new Session($storage);
```

Defining Factory Services
-------------------------

[](#defining-factory-services)

By default, each time you get a service, Pimple returns the **same instance**of it. If you want a different instance to be returned for all calls, wrap your anonymous function with the `factory()` method

```
$container['session'] = $container->factory(function ($c) {
    return new Session($c['session_storage']);
});
```

Now, each call to `$container['session']` returns a new instance of the session.

Defining Parameters
-------------------

[](#defining-parameters)

Defining a parameter allows to ease the configuration of your container from the outside and to store global values:

```
// define some parameters
$container['cookie_name'] = 'SESSION_ID';
$container['session_storage_class'] = 'SessionStorage';
```

If you change the `session_storage` service definition like below:

```
$container['session_storage'] = function ($c) {
    return new $c['session_storage_class']($c['cookie_name']);
};
```

You can now easily change the cookie name by overriding the `session_storage_class` parameter instead of redefining the service definition.

Protecting Parameters
---------------------

[](#protecting-parameters)

Because Pimple sees anonymous functions as service definitions, you need to wrap anonymous functions with the `protect()` method to store them as parameters:

```
$container['random_func'] = $container->protect(function () {
    return rand();
});
```

Modifying Services after Definition
-----------------------------------

[](#modifying-services-after-definition)

In some cases you may want to modify a service definition after it has been defined. You can use the `extend()` method to define additional code to be run on your service just after it is created:

```
$container['session_storage'] = function ($c) {
    return new $c['session_storage_class']($c['cookie_name']);
};

$container->extend('session_storage', function ($storage, $c) {
    $storage->...();

    return $storage;
});
```

The first argument is the name of the service to extend, the second a function that gets access to the object instance and the container.

Service providers
-----------------

[](#service-providers)

Simplex supports registering [cross-framework service providers](https://github.com/container-interop/service-provider).

To register service providers, pass an array of service providers as first constructor argument.

```
$container = new \Simplex\Container([new MyServiceProvider()]);
```

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community34

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.8% 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 ~119 days

Recently: every ~155 days

Total

7

Last Release

3062d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/329a6111724074f5388e95dd41a03ccf3c43f4bfe1ecf27c94c9efc6f7823228?d=identicon)[mnapoli](/maintainers/mnapoli)

---

Top Contributors

[![fabpot](https://avatars.githubusercontent.com/u/47313?v=4)](https://github.com/fabpot "fabpot (134 commits)")[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (23 commits)")[![igorw](https://avatars.githubusercontent.com/u/88061?v=4)](https://github.com/igorw "igorw (15 commits)")[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (11 commits)")[![bnf](https://avatars.githubusercontent.com/u/473155?v=4)](https://github.com/bnf "bnf (4 commits)")[![whatthejeff](https://avatars.githubusercontent.com/u/306525?v=4)](https://github.com/whatthejeff "whatthejeff (4 commits)")[![lyrixx](https://avatars.githubusercontent.com/u/408368?v=4)](https://github.com/lyrixx "lyrixx (4 commits)")[![davedevelopment](https://avatars.githubusercontent.com/u/61351?v=4)](https://github.com/davedevelopment "davedevelopment (4 commits)")[![stof](https://avatars.githubusercontent.com/u/439401?v=4)](https://github.com/stof "stof (3 commits)")[![mtdowling](https://avatars.githubusercontent.com/u/190930?v=4)](https://github.com/mtdowling "mtdowling (3 commits)")[![wouterj](https://avatars.githubusercontent.com/u/749025?v=4)](https://github.com/wouterj "wouterj (2 commits)")[![dominikzogg](https://avatars.githubusercontent.com/u/1011217?v=4)](https://github.com/dominikzogg "dominikzogg (2 commits)")[![gigr](https://avatars.githubusercontent.com/u/4009793?v=4)](https://github.com/gigr "gigr (2 commits)")[![mvriel](https://avatars.githubusercontent.com/u/193704?v=4)](https://github.com/mvriel "mvriel (1 commits)")[![pmall](https://avatars.githubusercontent.com/u/741677?v=4)](https://github.com/pmall "pmall (1 commits)")[![raphahardt](https://avatars.githubusercontent.com/u/4107730?v=4)](https://github.com/raphahardt "raphahardt (1 commits)")[![vlakarados](https://avatars.githubusercontent.com/u/386678?v=4)](https://github.com/vlakarados "vlakarados (1 commits)")[![jbboehr](https://avatars.githubusercontent.com/u/225601?v=4)](https://github.com/jbboehr "jbboehr (1 commits)")[![andylibrian](https://avatars.githubusercontent.com/u/1214976?v=4)](https://github.com/andylibrian "andylibrian (1 commits)")[![annesosensio](https://avatars.githubusercontent.com/u/3370605?v=4)](https://github.com/annesosensio "annesosensio (1 commits)")

---

Tags

dependency-injectionioccontainerdependency-injection

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mnapoli-simplex/health.svg)

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

###  Alternatives

[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k134.5M1.4k](/packages/pimple-pimple)[php-di/php-di

The dependency injection container for humans

2.9k55.5M1.2k](/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.

356990.7k60](/packages/aura-di)[acclimate/container

Provides adapters for various third-party service containers.

222396.7k15](/packages/acclimate-container)[mrclay/props-dic

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

3512.7M3](/packages/mrclay-props-dic)[slince/di

A flexible dependency injection container

20272.1k6](/packages/slince-di)

PHPackages © 2026

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