kecik/dic
最新稳定版本:1.0.3
Composer 安装命令:
composer require kecik/dic
包简介
DIC (Dependency Injection Container) Libraries for Kecik Framework
关键字:
README 文档
README
This library is a library supporters to support the Dependency Injection Container problems, so the library is an object, controller, it could be a model or library will be loaded only once, so as to avoid wastage.
Installation
file composer.json
{
"require": {
"kecik/dic": "dev-master"
}
}
run a command
composer install
Example Using
<?php require "vendor/autoload.php"; $config = array ( 'libraries' => array ( 'DIC' => array ( 'enable' => TRUE ) ), ); $app = new Kecik\Kecik($config); class Test1 { public function __construct() { echo "Hello is Test1 <br />"; } } class Test2 { public function __construct(Test1 $test) { echo "Hello is Test2 <br />"; } public function index() { echo 'Is Index'; } } $app->container['Test1'] = function($c) { return new Test1(); }; $app->container['Test2'] = function($c) { return new Test2($c['Test1']); }; $app->container['Test3'] = $app->container->factory(function($c) { return new Test2($c['Test1']); }); $app->get('/', function() use ($app){ $app->container['Test1']; $app->container['Test2']->index(); }); $app->run(); ?>
or for Controller
WelcomeController
file: welcome.php
<?php namespace Controller; use Kecik\Controller; class Welcome extends Controller { public function __construct() { echo 'Hello is Welcome Controller'; } }
HelloController
file: hello.php
<?php namespace Controller; use Kecik\Controller; class Hello extends Controller { public function __construct(Welcome $welcome) { echo 'Hello is Hello Controller'; } public function say($name) { echo "Hello, $name"; } }
Index
file: index.php
<?php require "vendor/autoload.php"; $config = array ( 'libraries' => array ( 'DIC' => array ( 'enable' => TRUE ) ), ); $app = new Kecik\Kecik($config); $app->container['WelcomeController'] = function($c) { return new Controller\Welcome(); }; $app->container['HelloController'] = function($c) { return new Controller\Hello($c['WelcomeController']); }; $app->get('/', function() use ($app){ $app->container['WelcomeController']; }); $app->get('hell/:name', function($name) use ($app) { $app->container['HelloController']->say($name); }); $app->run(); ?>
统计信息
- 总下载量: 154
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-01