Ako riesit viacero Trait ktore prepisuju jednu metodu?
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- duskohu
- Člen | 778
Caute ako riesite problem ked mate viacero trait ktore napr prepisuju
createComponent
?
Mam napr.:
abstract class BasePresenter extends Presenter {
use Kdyby\Autowired\AutowireComponentFactories
use Some\Another\Class\With\CreateComponent
protected function createComponent($name) {
$component = parent::createComponent($name);
// Set control template
$method = 'setTemplateFile';
if (method_exists($component, $method)) {
$list = $this->themeLoader->formatComponentTemplateFiles($this, $component);
foreach ($list as $file) {
if (is_file($file)) {
$component->$method($file);
}
}
}
return $component;
}
}
- greeny
- Člen | 405
Viz PHP dokumentace
<?php
use SomeTrait, SomeOtherTrait {
SomeTrait::createComponent as someTraitCreateComponent,
SomeOtherTrait::createComponent as someOtherTraitCreateComponent
}
protected function createComponent($name) {
$a = parent::someTraitCreateComponent($name);
$b = parent::someOtherTraitCreateComponent($name);
// do whatever with $a and $b
}
?>