Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- abstract class BaseControl extends Nette\Application\UI\Control {
- protected $translator;
- public function injectTranslator(Nette\Localization\ITranslator $translator) {
- $this->translator = $translator;
- }
- protected function createTemplate($class = NULL) {
- $template = parent::createTemplate($class);
- $template->registerHelperLoader('Helpers::loader');
- $template->setTranslator($this->translator);
- // ...
- return $template;
- }
- }
- final class RandomControlFactory extends ControlFactory {
- protected $dependency;
- public function __construct(RandomDependency $dependency) {
- $this->dependency = $dependency;
- }
- public function create() {
- return new RandomControl($this->dependency);
- }
- }
- final class RandomControl extends BaseControl {
- private $dependency;
- public function __construct(RandomDependency $dependency) {
- $this->dependency = $dependency;
- }
- public function attached($parent) {
- // Logic ..
- // I have $this->translator already
- }
- public function render() {
- // Render stuff
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment