PHPackages                             robotusers/cakephp-di - 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. robotusers/cakephp-di

ActiveCakephp-plugin[Utility &amp; Helpers](/categories/utility)

robotusers/cakephp-di
=====================

PSR-11 compatible CakePHP Dependency Injection Container abstraction plugin

0.2.1(5y ago)62.8k3MITPHPPHP &gt;=7.2

Since Aug 9Pushed 5y ago3 watchersCompare

[ Source](https://github.com/robotusers/cakephp-di)[ Packagist](https://packagist.org/packages/robotusers/cakephp-di)[ Docs](https://github.com/robotusers/cakephp-di)[ RSS](/packages/robotusers-cakephp-di/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (6)Dependencies (5)Versions (10)Used By (0)

CakePHP DI
==========

[](#cakephp-di)

[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![codecov](https://camo.githubusercontent.com/c59efd5627528691d169d3749c989ed09666e9205beae42f6c4ee40cd7291ec5/68747470733a2f2f636f6465636f762e696f2f67682f726f626f7475736572732f63616b657068702d64692f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/robotusers/cakephp-di)

PSR-11 compatible CakePHP Dependency Injection Container abstraction plugin

Under development
-----------------

[](#under-development)

The plugin is under development and not intended to use in production yet.

Versions
--------

[](#versions)

For CakePHP 3.x use CakePHP DI 0.1.x versions. CakePHP DI 0.2.x is intended for CakePHP 4.0 and 4.1

For CakePHP 4.2 try [0.3](https://github.com/robotusers/cakephp-di/tree/0.3) branch

Container Abstraction
---------------------

[](#container-abstraction)

This plugin provides tools for using any PSR-11 compatible DIC with CakePHP framework. DIC support for CakePHP is a very frequently requested feature. Although CakePHP is build with Dependency Injection in mind, it does not provide any build-in DIC. There are many great DI Containers out there and this plugin allows you to choose the one you like the most and use it with your CakePHP app.

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

[](#configuration)

CakePHP DI plugin provides a `Robotusers\DI\Core\ContainerApplicationInterface`that your `Application` class should implement. This interface defines a `getContainer()` method that should return your PSR-11 compatible container.

The plugin provides a base application class that you can extend.

```
class Application extends \Robotusers\DI\Http\BaseApplication
{
    protected function createContainer()
    {
        $container = new SomeContainer();

        //configure your services

        return $container;
    }
}
```

Note that the base class requires you to implement `createContainer()` method. That is a factory method for your container as `getContainer()` needs to return the same instance on each call.

The `BaseApplication` class also provides some wiring for action dispatcher so the controllers and actions use your DI Container.

Controllers
-----------

[](#controllers)

Controllers should be registered as a service in your DIC. The plugin tries to retrieve a controller from your DIC with the controller's FQCN as an id. For example: `$container->get('App\Controller\ArticlesController')`;

The plugin also provides the ability to inject services into controller actions.

The services must be passed as a parameters to the action method. The precedence take the passed parameters, so for example your `view` method should look like this:

```
//ArticlesController.php

public function view($id, ArticlesServiceInterface $service)
{
    //code
}
```

The `ArticlesServiceInterface` instance will be injected into the method.

Console
-------

[](#console)

In order to fetch a console command from a DIC you need to use a `CommandFactory` provided with this plugin.

In your `bin/cake.php`:

```
...

use App\Application;
use Cake\Console\CommandRunner;
use Robotusers\Di\Console\CommandFactory;

$application = new Application(dirname(__DIR__) . '/config');
$factory = new CommandFactory($application);
$runner = new CommandRunner($application, 'cake', $factory);
exit($runner->run($argv));
```

Table Locator
-------------

[](#table-locator)

Extending `Robotusers\DI\Http\BaseApplication` provides you with a DIC aware implementation of `TableLocator`. During the bootstrapping process the global instance of table locator is injected into `TableRegistry`.

Table locator replacement shipped with this plugin allows you to inject your own table factory.

By default a `ContainerFactory` is used which retrieves a table from your DIC using table's class name as an `$id`. Note that options are not passed to the DIC as PSR-11 implementation does not support passing extrac arguments to the `get()` method.

You either need to configure your table options using `TableLocator::setConfig()`method or configure your container to pass correct options.

You can also use custom implementation of table factory by overriding `Application::createTableLocator()` method. Table factory must be a callable that accepts `$options` array.

```
protected function createTableLocator()
{
    $factory = function($options) {
        // retrieve a table from your DIC

        return $table;
    };

    return new \Robotusers\Di\ORM\Locator\TableLocator($factory);
}
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.7% 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 ~120 days

Recently: every ~5 days

Total

9

Last Release

1879d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.6

0.2.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ea7e55d797f61a7a0448f1b88cfd5b855e9644c7909af356a82896587926197?d=identicon)[robertpustulka](/maintainers/robertpustulka)

---

Top Contributors

[![robertpustulka](https://avatars.githubusercontent.com/u/7437773?v=4)](https://github.com/robertpustulka "robertpustulka (76 commits)")[![ADmad](https://avatars.githubusercontent.com/u/142658?v=4)](https://github.com/ADmad "ADmad (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/robotusers-cakephp-di/health.svg)

```
[![Health](https://phpackages.com/badges/robotusers-cakephp-di/health.svg)](https://phpackages.com/packages/robotusers-cakephp-di)
```

###  Alternatives

[illuminate/container

The Illuminate Container package.

31278.1M2.0k](/packages/illuminate-container)[symfony/type-info

Extracts PHP types information.

19751.9M114](/packages/symfony-type-info)[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

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

728272.9k20](/packages/civicrm-civicrm-core)[dereuromark/cakephp-tools

A CakePHP plugin containing lots of useful and reusable tools

338920.1k32](/packages/dereuromark-cakephp-tools)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)

PHPackages © 2026

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