osflab / container
OSF dynamic object container mechanism
Requires
- php: ^7.1.0
- osflab/exception: ~3.0.0
Requires (Dev)
- osflab/test: ~3.0.0
Suggests
- ext-redis: *
- osflab/application: ~3.0.0
- osflab/cache: ~3.0.0
- osflab/controller: ~3.0.0
- osflab/crypt: ~3.0.0
- osflab/device: ~3.0.0
- osflab/doc-maker: ~3.0.0
- osflab/navigation: ~3.0.0
- osflab/session: ~3.0.0
- osflab/stream: ~3.0.0
- osflab/view: ~3.0.0
- twig/twig: 2.4.4
- zendframework/zend-authentication: 2.5.3
- zendframework/zend-db: 2.9.2
- zendframework/zend-i18n: 2.7.4
- zendframework/zend-i18n-resources: 2.5.2
Provides
- osflab/application: 3.0.0
- osflab/controller: 3.0.0
- osflab/db: 3.0.0
- osflab/device: 3.0.0
- osflab/doc-maker: 3.0.0
- osflab/form: 3.0.0
- osflab/image: 3.0.0
- osflab/navigation: 3.0.0
- osflab/office: 3.0.0
- osflab/pdf: 3.0.0
- osflab/safety: 3.0.0
- osflab/stream: 3.0.0
- osflab/view: 3.0.0
This package is not auto-updated.
Last update: 2025-03-02 07:12:03 UTC
README
OSF Container manages instances of your classes in order to optimize performance and accessibility. Define the instantiation policy of each class and let OSF Container create and manage your objects.
Features
- Lazy classes instanciations
- Optimized management of the instantiation policy
- Dependency management
- Mock objects generation & advanced mocking policy
- Extremely simplified access to objects
Installation
You need at least php 7.1 and composer
:
sudo apt install composer
In your application via composer
This is the recommended way to use this feature in a non-osf project.
Just add osflab/container
in your composer.json file.
From github
To test the component or participate in its development.
git clone https://github.com/osflab/container.git cd container && composer update
Unit tests launch:
vendor/bin/runtests
Usage
For example, to use Osf\Cache
component (anyware in your code):
$cache = \Osf\Container\OsfContainer::getCache();
To create your own container:
use Osf\Container\AbstractContainer; class MyContainer extends AbstractContainer { /** * Build and get on-demand \My\Class instance(s) * @return \My\Class */ public static function getMyClass(): \My\Class { return self::buildObject('\My\Class'); } }
The AbstractContainer::buildObject()
method takes 3 args:
- The class name
- An array of class constructor values
- A namespace string
See OsfContainer
, ZendContainer
and VendorContainer
for more examples.