PHPackages                             gquental/cakephp-service-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. [Framework](/categories/framework)
4. /
5. gquental/cakephp-service-container

ActiveCakephp-plugin[Framework](/categories/framework)

gquental/cakephp-service-container
==================================

Service Container for CakePHP

0.0.8(12y ago)71272MITPHP

Since Feb 5Pushed 12y ago1 watchersCompare

[ Source](https://github.com/gquental/cakephp-service-container)[ Packagist](https://packagist.org/packages/gquental/cakephp-service-container)[ Docs](https://github.com/gquental/cakephp-service-container)[ RSS](/packages/gquental-cakephp-service-container/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (10)Used By (0)

cakephp-service-container
=========================

[](#cakephp-service-container)

This project was created to provide the feature of a container of services and also dependency injection in the CakePHP framework.

\##Installation

In order to install it, there is two options, install it through composer or manually.

\###composer

You just need to require the package **gquental/cakephp-service-container** in your **composer.json** and then run the install command. After this process is completed, a folder called **ServiceContainer** will be created inside your CakePHP plugins folder.

\###manually

Just clone the project inside your CakePHP plugins folder and name the directory **ServiceContainer**

\##Usage

\###Configuration file

The first step after the Plugin is properly installed is to create the configuration file and then register it in the CakePHP config bootstrap file **(app/Config/bootstrap.php)**.

For example, if you name the file **services.php**, you will need to write this line in your bootstrap file:

```
// First parameter is the name of the file without the extension
// The second parameter is the name of the configuration reader,
// which in CakePHP the default is the PHP file reader
Configure::load('services', 'default');
```

\####Configuration file example

```
$config = array(
	'Services' => array(
		'ServiceName' => array(
			'name' => 'name of the class',
			'path' => 'path of the class'
			'arguments' => [1, 2, 3]
		)
	)
);
```

\###Using the ServiceContainer Component

In order to call the services inside the container, you will need to use the CakePHP component provided by the Plugin, in order to do so you will need to put the following entry in the components array.

```
$components = ['ServiceContainer.ServiceContainer'];
```

With the component prepared, you can call a service by calling the **getService** method.

```
public function actionX() {
	$service = $this->ServiceContainer->getService('serviceName');
}
```

\###Dependency injection

Lets say that in your container we have two classes, the User and the Contact class. The contact class needs as a dependency the user instance and also a integer with the maximum number of phones that it should have.

We can pass all of this dependencies through the service container instead of instancing it manually in the Contact class. In order to do so we will to pass arguments to the Contact class in the services container configuration file.

In the arguments we can pass primitive values or another service already in the configuration file, only by passing a string with the name of the service preceded by a **@**, like this for the user class: **"@User"**.

Below you will find the examples of how to create this situation

**app/Config/services.php**

```
$config = array(
	'Services' => array(
		'User' => array(
			'name' => 'UserEntity',
			'path' => 'Lib'
		),
		'Contact' => array(
			'name' => 'ContactEntity',
			'path' => 'Lib',
			'arguments' => ['@User', 3]
		)
	)
);
```

**someController.php**

```
public function action() {
	$contact = $this->ServiceContainer->get('Contact');
}
```

**Lib/UserEntity.php**

```
class UserEntity {}
```

**Lib/ContactEntity.php**

```
class ContactEntity {
	public $user;
	public $maxPhones;

	public function __construct($user, $maxPhones) {
		$this->user = $user;
		$this->maxPhones = $maxPhones;
	}
}
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96% 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 ~1 days

Total

8

Last Release

4468d ago

### Community

Maintainers

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

---

Top Contributors

[![gquental](https://avatars.githubusercontent.com/u/844113?v=4)](https://github.com/gquental "gquental (24 commits)")[![pmoraes](https://avatars.githubusercontent.com/u/5813004?v=4)](https://github.com/pmoraes "pmoraes (1 commits)")

### Embed Badge

![Health badge](/badges/gquental-cakephp-service-container/health.svg)

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

###  Alternatives

[silverstripe/framework

The SilverStripe framework

7213.5M2.5k](/packages/silverstripe-framework)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[drupal/recommended-project

Project template for Drupal projects with a relocated document root

1502.6M1](/packages/drupal-recommended-project)[elgg/elgg

Elgg is an award-winning social networking engine, delivering the building blocks that enable businesses, schools, universities and associations to create their own fully-featured social networks and applications.

1.7k15.7k5](/packages/elgg-elgg)[october/rain

October Rain Library

1601.7M63](/packages/october-rain)[juzaweb/cms

Juzaweb CMS is a Content Management System (CMS) developed based on Laravel Framework and web platform whose sole purpose is to make your development workflow simple again. Project develop by Juzaweb

187571.2k](/packages/juzaweb-cms)

PHPackages © 2026

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