1
0
Fork
You've already forked container
0
A PSR-11 compatible dependency injection library
  • PHP 100%
Thomas Ernst f8d00c5a3b
All checks were successful
ci / ci (push) Successful in 1m20s
Update README badges
2026年06月10日 21:22:55 +02:00
.forgejo/workflows Allow manual CI runs 2026年06月10日 20:58:18 +02:00
.github Add GitHub mirror README 2026年06月10日 21:14:39 +02:00
docs Update docs tooling 2026年05月12日 15:00:38 +02:00
src The big rename 2026年05月11日 14:07:22 +02:00
tests The big rename 2026年05月11日 14:07:22 +02:00
.editorconfig Sync shared config files 2026年01月30日 22:07:57 +01:00
.gitattributes Update .gitattributes 2026年04月15日 21:00:02 +02:00
.gitignore Update .gitignore 2026年04月13日 16:54:38 +02:00
CHANGELOG.md Update changelog 2026年06月10日 18:34:13 +02:00
composer.json Require dev package v4.2 2026年05月13日 13:12:06 +02:00
LICENSE.md Update license 2026年05月12日 19:44:41 +02:00
mago.toml Update mago.toml 2026年04月15日 16:11:53 +02:00
phpunit.xml.dist Update coverage config 2026年05月12日 19:41:02 +02:00
psalm.xml.dist Use xml.dist config names 2026年05月11日 14:55:02 +02:00
README.md Update README badges 2026年06月10日 21:22:55 +02:00

Celemas Container

ci code coverage type coverage psalm level Software License

A PSR-11 compatible dependency injection container.

Entry lifetimes

Container entries use explicit lifetimes:

  • shared() caches one instance per container (default for added entries)
  • scoped() caches one instance per requesting container scope
  • transient() never caches
  • value() returns the configured definition as-is (for literals or raw closures)
$container->add('config', ['debug' => true])->value();
$container->add(Service::class)->shared();
$container->add(RequestContext::class)->scoped();
$container->add(Builder::class)->transient();

Scope mode

Use scope() to create an isolated container for one unit of work:

$root = new Container();
$root->add('app-name', 'celemas')->value();
$root->add('global-service', GlobalService::class)->shared();
$root->add('request-service', RequestService::class)->scoped();
$scope = $root->scope();
$scope->add(Request::class, $request)->value();
// ... resolve request-local services
$scope->reset();

After the first scope() call, the root container is sealed and no longer accepts structural mutations. Scope tags can inherit pre-defined root tags while keeping their own local caches.

Services that should be cleaned between scopes can implement Celemas\Container\Resettable and will be reset during $scope->reset().

License

This project is licensed under the MIT license.