nurse/di
Composer 安装命令:
composer require nurse/di
包简介
Dependency injection library
README 文档
README
Very simple Dependency Injection Container for PHP
Code information:
Package information:
Installing
Installing via Composer
Append the lib to your requirements key in your composer.json.
{ // composer.json // [..] require: { // append this line to your requirements "nurse/di": "dev-master" } }
For PHP 5.3 and 5.4 support use version 0.9.2.
Alternative install
- Learn composer. You should not be looking for an alternative install. It is worth the time. Trust me ;-)
- Follow this set of instructions
Issues/Features proposals
Here is the issue tracker.
Usage
Defining a dependency:
$container = new Nurse\Container; // Defining a dependency $container->set('connection', function ($container) { $params = $container->get('connection_params'); return new Connection($params); }) ->set('connection_params', function () { return array( 'schema' => 'someschema', 'username' => 'root', 'password' => 's3cr3t', ); }); // Retrieving the dependency (lazy loading) $connection = $container->get('connection'); // alternatively you can use the singleton instance of the container Nurse\Di::set('connection', function ($container) { $params = $container->get('connection_params'); return new Connection($params); }) ->set('connection_params', function () { return array( 'schema' => 'someschema', 'username' => 'root', 'password' => 's3cr3t', ); }); $connection = Nurse\Di::get('connection');
You can also create factories:
<?php namespace App; use Nurse\Factory\FactoryInterface; use Psr\Container\ContainerInterface; class ConnectionFactory implements FactoryInterface { public function createService(ContainerInterface $container) { $params = $container->get('connection_params'); return new Connection($params); } public function getKey() { return 'connection'; } }
And then:
$factory = new \Dummy\MyDummyFactory(); $actual = $container->addFactory($factory);
Contributing
Please refer to the contribuiting guide.
License
Authors
- Marcelo Jacobus
- Maicon Pinto
- Anthonny Machado
- Emerson Engroff
- Daniel Caña
- Elisandro Nabienger
统计信息
- 总下载量: 2.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-06-23