PHPackages                             mtchabok/container\_light - 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. mtchabok/container\_light

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

mtchabok/container\_light
=========================

A lightweight, fast, and flexible container for managing resources (values, functions, objects, etc.)

1.0.15(5mo ago)110MITPHPPHP &gt;=8.1

Since Sep 9Pushed 5mo agoCompare

[ Source](https://github.com/mtchabok/container_light)[ Packagist](https://packagist.org/packages/mtchabok/container_light)[ RSS](/packages/mtchabok-container-light/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (2)Versions (7)Used By (0)

PHP Container Light
===================

[](#php-container-light)

A lightweight and fast PHP container that has been designed to operate efficiently while maintaining high flexibility (customization capabilities) in resource consumption. It is a suitable option for resource management in any type of project.

Some of the features of this container:

- Definition of values, functions, classes with name and namespace (namespace.name)
- Possibility of defining a group as an array or file and managing it with a namespace that is processed if necessary
- Definition of before and after events and desired events to control input and output parameters
- Storage of values, objects or function results permanently or temporarily
- Possibility of protecting against unwanted changes to values
- Control of infinite loops at runtime
- Ability to set class and function inputs to create an object or execute a function
- Definition of aliases for main names with the possibility of various settings
- Execution of events along the path of the defined namespace so that events are executed in one path from the root to the destination
- Events are defined based on the namespace, and it is possible to execute each event on multiple sources
- Cache the way objects are created or functions are executed to improve performance and consumption management Resources
- Ability to define resources in a completely flexible way using file
- Versatile access to resources using methods, virtual properties and virtual methods

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

[](#installation)

Use the package manager [composer](https://getcomposer.org/) to install mtchabok container light.

```
composer require mtchabok/container_light
```

How To Usage
------------

[](#how-to-usage)

```
$container = new \MCL\Container();
$container->add([
    'prepareMessage'=>function(string $message){ return ".:[ $message ]:."; },
    'showMessage'=>function (string $message) use ($container) { echo $container->prepareMessage($message); },
]);
$container->showMessage('test message!');
```

```
.:[ test message! ]:.

```

### add array resource into container

[](#add-array-resource-into-container)

```
$container = new \MCL\Container();
$container->add([
    'prepareMessage'=>function(string $message){ return ".:[ $message ]:."; },
    'showMessage'=>function (string $message) use ($container) { echo $container->prepareMessage($message); },
    'test'=>function(){ return "\nHello World!"; },
    'test2'=>fn() => "\nHow Are You?",
    'test3'=>"\nI`m Fine!",
    'uniqid' => \MCL\Resource\Definition::createCallable('uniqid'),
    'uniq' =>  \MCL\Resource\Definition::createAlias('uniqid')->shared(true),
    'p1' => \MCL\Resource\Definition::createValue('good')->protected(true),
    ':params' => function($p,$c,$id){ echo "\n[on params of '$id'] "; },
    ':after' => function($p, $c, $id){ return is_string($p) ?"$p [after on: $id]" :$p; },
]);
```

### add closure resources into container

[](#add-closure-resources-into-container)

```
$container = new \MCL\Container();
$container->add(
    function (\MCL\Resource\Source $source, \MCL\Container $container) {
        return [
            'prepareMessage'=>function(string $message){ return ".:[ $message ]:."; },
            'showMessage'=>function (string $message) use ($container) { echo $container->prepareMessage($message); },
            'test'=>function(){ return "\nHello World!"; },
            'test2'=>fn() => "\nHow Are You?",
            'test3'=>"\nI`m Fine!",
            'uniqid' => $source->callable('uniqid'),
            'uniq' => $source->alias('uniqid')->shared(true),
            'p1' => $source->value('good')->protected(true),
            ':params' => function($p,$c,$id){ echo "\n[on params of '$id'] "; },
            ':after' => function($p, $c, $id){ return is_string($p) ?"$p [after on: $id]" :$p; },
        ];
    }
);
```

### add file resource into container

[](#add-file-resource-into-container)

content of php file : source.php

```
use MCL\Resource\Source;
/** @var Source $this */
$container = $this->container;
return [
    'prepareMessage'=>function(string $message){ return ".:[ $message ]:."; },
    'showMessage'=>function (string $message) use ($container) { echo $container->prepareMessage($message); },
    'test'=>function(){ return "\nHello World!"; },
    'test2'=>fn() => "\nHow Are You?",
    'test3'=>"\nI`m Fine!",
    'uniqid' => $this->callable('uniqid'),
    'uniq' => $this->alias('uniqid')->shared(true),
    'p1' => $this->value('good')->protected(true),
    ':params' => function($p,$c,$id){ echo "\n[on params of '$id'] "; },
    ':after' => function($p, $c, $id){ return is_string($p) ?"$p [after on: $id]" :$p; },
];
```

and add source file into container

```
$container = new \MCL\Container();
$container->add('source.php');
```

### share resource

[](#share-resource)

```
$container = new \MCL\Container();
$container->add(['uniqid'=>\MCL\Resource\Definition::createCallable('uniqid')->shared(true)]);
echo $container->uniqid()."\n";
echo $container->uniqid()."\n";
echo $container->uniqid()."\n";
```

```
69539660cf1d7
69539660cf1d7
69539660cf1d7

```

### protect resource

[](#protect-resource)

```
$container = new \MCL\Container();
$container->add(['uniqid'=>fn () => 'text unique']);
$container->add(['uniqid'=>\MCL\Resource\Definition::createCallable('uniqid')->protected(true)]);
$container->add(['uniqid'=>'wow']);
echo $container->uniqid()."\n";
```

```
695397811b56c

```

### customize resource arguments

[](#customize-resource-arguments)

```
$container = new \MCL\Container();
$container->add([
    'message' => 'test message!',
    'showMessage'=>\MCL\Resource\Definition::createCallable(function (string $message) use ($container) { return "msg: $message\n"; })
        ->parameters(function ($args) use ($container) {
            return !empty($args) ?$args :[$container->message];
        }),
]);
echo $container->showMessage();
echo $container->showMessage('another message!');
```

```
msg: test message!
msg: another message!

```

### alias name of resource

[](#alias-name-of-resource)

```
$container = new \MCL\Container();
$container->add([
    'uniqid' => \MCL\Resource\Definition::createCallable('uniqid'),
    'uniq' => \MCL\Resource\Definition::createAlias('uniqid')->shared(true),
]);
echo '1. uniqid: '.$container->uniqid()."\n";
echo '2. uniq: '.$container->uniq()."\n";
echo '3. uniqid: '.$container->uniqid()."\n";
echo '4. uniq: '.$container->uniq()."\n";
```

```
1. uniqid: 6953a0fa81499
2. uniq: 6953a0fa814c4
3. uniqid: 6953a0fa814d7
4. uniq: 6953a0fa814c4

```

### event on resource

[](#event-on-resource)

```
$container = new \MCL\Container();
$container->add([
    'uniqid' => \MCL\Resource\Definition::createCallable('uniqid'),
    'uniq' => \MCL\Resource\Definition::createAlias('n1.uniqid')->shared(true),
],'n1');
$container->add([ ':after' => function ($p) { return "$p [2]"; } ],'n1');
$container->add([ ':after' => function ($p) { return "$p [1]"; } ]);
echo '1. uniqid: '.$container->call('n1.uniqid')."\n";
echo '2. uniq: '.$container->call('n1.uniq')."\n";
echo '3. uniqid: '.$container->call('n1.uniqid')."\n";
echo '4. uniq: '.$container->call('n1.uniq')."\n";
```

```
1. uniqid: 6953a204b37f8 [1] [2]
2. uniq: 6953a204b383a [1] [2] [1] [2]
3. uniqid: 6953a204b3859 [1] [2]
4. uniq: 6953a204b383a [1] [2] [1] [2]

```

License
-------

[](#license)

MIT License. See the LICENSE file.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance69

Regular maintenance activity

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

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

Total

6

Last Release

179d ago

Major Versions

0.5.0 → 1.0.122026-01-01

PHP version history (2 changes)0.4.0PHP &gt;=8.0

1.0.12PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/27890892?v=4)[Mohamad Taqi Chabok](/maintainers/mtchabok)[@mtchabok](https://github.com/mtchabok)

---

Top Contributors

[![mtchabok](https://avatars.githubusercontent.com/u/27890892?v=4)](https://github.com/mtchabok "mtchabok (41 commits)")

---

Tags

phpcontainerdependency-injection

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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