osflab/container
Composer 安装命令:
composer require osflab/container
包简介
OSF dynamic object container mechanism
README 文档
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.
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 13
- 推荐数: 6
其他信息
- 授权协议: AGPL-3.0-or-later
- 更新时间: 2018-02-05