frizzy / container
PHP Container
Installs: 23
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/frizzy/container
Requires
- php: >=5.3.0
- frizzy/map: ~1.0
This package is not auto-updated.
Last update: 2025-10-20 21:18:28 UTC
README
Usage
Add the following to your root composer.json file:
{
"require": {
"frizzy/container": "~1.0"
}
}
Add a factory:
<?php $container = new \Frizzy\Container\Container; $container->set( 'myFactory', function ($container) { return new \stdClass } ); ?>
Add a shared factory:
<?php $container = new \Frizzy\Container\Container; $container->share( 'mySharedFactory', function ($container) { return new \stdClass } ); ?>
Add a protected closure:
<?php $container = new \Frizzy\Container\Container; $container->protect( 'myProtectedClosure', function ($value) { return ucfirst($value); } ); ?>
Extend a factory:
<?php $container = new \Frizzy\Container\Container; $container->share( 'mySharedFactory', function ($container) { return new \stdClass } ); $container->extend( 'mySharedFactory', function ($container, $service) { $service->date = new \DateTime(); $service->name = $container->get('otherService')->getName(); } ); ?>