PHPackages                             caridea/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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. caridea/container

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

caridea/container
=================

A shrimp of a dependency injection library

3.0.1(8y ago)06353Apache-2.0PHPPHP &gt;=7.1.0

Since Jun 3Pushed 8y ago1 watchersCompare

[ Source](https://github.com/libreworks/caridea-container)[ Packagist](https://packagist.org/packages/caridea/container)[ Docs](http://github.com/libreworks/caridea-container)[ RSS](/packages/caridea-container/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (13)Used By (3)

caridea-container
=================

[](#caridea-container)

Caridea is a miniscule PHP application library. This shrimpy fellow is what you'd use when you just want some helping hands and not a full-blown framework.

[![](https://camo.githubusercontent.com/3a9d2bd9abd336c1541d254cd07f8dff935288ad4a0983294f0b3f572f5b0f4b/687474703a2f2f6c69627265776f726b732e636f6d2f636172696465612d3130302e706e67)](https://camo.githubusercontent.com/3a9d2bd9abd336c1541d254cd07f8dff935288ad4a0983294f0b3f572f5b0f4b/687474703a2f2f6c69627265776f726b732e636f6d2f636172696465612d3130302e706e67)

This is its [PSR-11](http://www.php-fig.org/psr/psr-11/) compliant dependency injection container.

[![Packagist](https://camo.githubusercontent.com/c5209d5aac01b4a6bebcb3bb3b3a2b5578af7de71d93375229ff73433e43ff20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636172696465612f636f6e7461696e65722e737667)](https://packagist.org/packages/caridea/container)[![Build Status](https://camo.githubusercontent.com/2723d14c7ca3524f74a81afd5aff9d90f34c0758ba9c68113d9d68b074d0a64e/68747470733a2f2f7472617669732d63692e6f72672f6c69627265776f726b732f636172696465612d636f6e7461696e65722e737667)](https://travis-ci.org/libreworks/caridea-container)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2dcddce27c40a99484e220a968edf198df2c5dcb424de987479a6acf56e6cab1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c69627265776f726b732f636172696465612d636f6e7461696e65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/libreworks/caridea-container/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/15fcca882caf084269ac6bf79efe1cdacc4c859837f984172dee22bdeca66cbc/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c69627265776f726b732f636172696465612d636f6e7461696e65722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/libreworks/caridea-container/?branch=master)

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

[](#installation)

You can install this library using Composer:

```
$ composer require caridea/container
```

- The master branch (version 3.x) of this project requires PHP 7.1 and depends on `caridea/event`.
- Version 2.x of this project requires PHP 7.0 and depends on `caridea/event`.
- Version 1.x of this project requires PHP 5.5 and depends on `caridea/event`.

Compliance
----------

[](#compliance)

Releases of this library will conform to [Semantic Versioning](http://semver.org).

Our code is intended to comply with [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/), and [PSR-4](http://www.php-fig.org/psr/psr-4/). If you find any issues related to standards compliance, please send a pull request!

Overview
--------

[](#overview)

- The `Caridea\Container\Properties` class is intended for scalar configuration values that might be used as settings for other components.
- The `Caridea\Container\Objects` class allows for eager, lazy, and prototype objects.
    - It also implements `Caridea\Event\Publisher` and will broadcast events to any managed object which implements `Caridea\Event\Listener`.
- The `Caridea\Container\EmptyContainer` class is an empty, no-op container.

You can retrieve contained objects both by name and by type!

Documentation
-------------

[](#documentation)

- Head over to [Read the Docs](http://caridea-container.readthedocs.io/en/latest/)

Examples
--------

[](#examples)

Just a few quick examples.

### Configuration and Dependencies

[](#configuration-and-dependencies)

```
$config = [
    'db.uri' => 'mongodb://localhost:27017',
    'mail.host' => '192.168.1.100'
];
$properties = new \Caridea\Container\Properties($config);
$objects = \Caridea\Container\Objects::builder()
    ->eager('mongoClient', 'MongoClient', function($c){
        return new \MongoClient($c->get('db.uri'));
    })
    ->lazy('mailService', 'My\Mail\Service', function($c){
        return new \My\Mail\Service($c->('mail.host'));
    })
    ->lazy('userService', 'My\User\Service', function($c){
        return new \My\User\Service($c->get('mongoClient'), $c->get('objectStorage'));
    })
    ->proto('objectStorage', 'SplObjectStorage', function($c){
        return new \SplObjectStorage();
    })
    ->build($properties);

$userService = $objects->get('userService');
```

### Parent Delegation

[](#parent-delegation)

You can nest Objects containers. For example, you can have a container with service objects and a child container with web controllers.

```
$services = \Caridea\Container\Objects::builder()
    ->eager('blogService', 'My\Blog\Service', function($c){
        return new \My\Blog\Service();
    })
    ->build();
$controllers = \Caridea\Container\Objects::builder()
    ->eager('blogController', 'My\Blog\Controller', function($c){
        return new \My\Blog\Controller($c->get('blogService'));
    })
    ->build($services);

$controllers = $controllers->getByType('My\Blog\Controller'); // ['blogController' => BlogController]
```

### Events

[](#events)

```
$objects = \Caridea\Container\Objects::builder()
    ->eager('eventListener', 'My\Cool\EventListener', function($c){
        // we are assuming that this class implements Caridea\Event\Listener
        return new \My\Cool\EventListener();
    })
    ->build();

// assuming that CustomEvent implements Caridea\Event\Event
$objects->publish(new CustomEvent());
// Here, the eventListener object will have its ->notify() method invoked with the CustomEvent
```

Any objects returned from an `Objects` container that implement `\Caridea\Event\PublisherAware` will receive the container via the `setPublisher` method.

### ContainerAware

[](#containeraware)

Any objects returned from an `Objects` container that implement `\Caridea\Container\ContainerAware` will receive the container via the `setContainer` method. We provide a trait to make this easier.

```
class MyContainerAware implements \Caridea\Container\ContainerAware
{
    use \Caridea\Container\ContainerSetter;

    public function __construct()
    {
        $this->container = new \Caridea\Container\EmptyContainer();
    }
}
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

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

Recently: every ~118 days

Total

12

Last Release

3054d ago

Major Versions

0.1.0 → 1.0.02016-03-21

1.x-dev → 2.0.02016-03-22

2.2.x-dev → 3.0.02018-01-02

PHP version history (3 changes)0.1.0PHP &gt;=5.5.0

2.0.0PHP &gt;=7.0.0

3.0.0PHP &gt;=7.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/659262eac941ffe4795493834425fc9a2369c2c9df3cc565ed4194f1d37be934?d=identicon)[doublecompile](/maintainers/doublecompile)

---

Top Contributors

[![doublecompile](https://avatars.githubusercontent.com/u/4267230?v=4)](https://github.com/doublecompile "doublecompile (35 commits)")

---

Tags

PSR-11dependency-injectiondiiocinversion of control

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/caridea-container/health.svg)

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-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)
