17/09
2015
Wallogit.com
2017 © Pedro Peláez
php simple injection
PHP Simple Injection, use classe in project., (*1)
Composer install, (*3)
{
"require":"carlosocarvalho/coci": "1.0.0"
}
<?php require "vendor/autoload.php"; use COC\COCI\Injection; $inj = new Injection;
Create Classes Injections with Agregration (Person), (*4)
Class Person(){
private $person ;
class function __construct(TypePerson $typePerson){
$this->person = $typePerson;
}
}
Create Classes Injections(TypePerson), (*5)
<?php
Class TypePerson(){
private $type;
setType($type){
$this->type;
}
getType(){
return $this->type;
}
}
Inject Classes Closure, (*6)
<?php
$inj->set('TypePerson',function(){
return new TypePerson();
})
$inj->set('Person',function() use ($inj){
return new Person($inj->get('TypePerson'));
});
Inject Classes By Reflection, (*7)
<?php
$inj->get('TypePerson');