I would like to use traits to instanciate my objects with my DIC:
trait TUseContainer {
protected $c;
public function __construct(Container $c) {
$this->c=$c;
}
}
class MyClass {
use TUseContainer;
//Optional
public function __construct(ClassInheritedFromContainer $c){
TUseContainer::__construct($c);
//MyClass __construct stuff
}
}
So my questions are:
All coments are welcome, thanks.
I'll do some tests and post results.
I got some trivial workaround:
trait TUseContainer {
protected $c;
public function __construct(Container $c) {
$this->setContainer($c);
}
protected function setContainer(Container $c){
$this->c=$c;
}
}
class MyClass {
use TUseContainer;
//Optional
public function __construct(ClassInheritedFromContainer $c){
$this->setContainer($c);
//MyClass __construct stuff
}
}
All coments are still welcome
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.