/ Published in: PHP
Very usefull lite dependency injection for PHP5.
Usage:
di exends fuselogic_container()
{
function __construct()
{
parant::__construct(__FILE__);
}
}
safe this to the folder with others class with name "class.class_name.php'
then you can do like bellow
$di = new di();
$c1 = $di->class_x; //singleton
$c2 = $di->class_x; //singleton
$c3 = $di->class_x(); //not singleton
Usage:
di exends fuselogic_container()
{
function __construct()
{
parant::__construct(__FILE__);
}
}
safe this to the folder with others class with name "class.class_name.php'
then you can do like bellow
$di = new di();
$c1 = $di->class_x; //singleton
$c2 = $di->class_x; //singleton
$c3 = $di->class_x(); //not singleton
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//PHP5 only class fuselogic_container { function __construct($path = null) { { $instances[$class_name] = $this; } { $this->$var = &$instances[$class_name]->$var; } } function __get($name) { { return $this->__x[$lowercase]; }else { $this->__x[$lowercase] = $this->$name(); $instance = &$this->__x[$lowercase]; return $instance; } } function __call($name,$var) { { { return new $name($var[0]); }else { return new $name(); } }else { $this->_start(); if(@include_once('class.'.$name.'.php')) { return new $name(); } $this->_end(); } } function _start() { } function _end() { } function __set($name,$val) { $this->__x[$name] = $val; } function __isset($name) { { return true; { return true; }else return false; } }