Last active
August 29, 2015 14:02
-
-
Save fprochazka/728e0bdf93b40a8fd771 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @method onAttached(BaseControl $control, Nette\Application\UI\PresenterComponent $parent) | |
| * @method \BasePresenter getPresenter() | |
| * | |
| * @property \BasePresenter|BaseControl[] $presenter | |
| * @property-read \BasePresenter|BaseControl[] $presenter | |
| * @property \Nette\Templating\FileTemplate|\stdClass $template | |
| * @property-read \Nette\Templating\FileTemplate|\stdClass $template | |
| */ | |
| abstract class BaseControl extends Nette\Application\UI\Control | |
| { | |
| use \Kdyby\Autowired\AutowireComponentFactories; | |
| /** | |
| * @var array of function (BaseControl $control, Nette\ComponentModel\Container $parent) | |
| */ | |
| public $onAttached = array(); | |
| /** | |
| * @var Nette\DI\Container | |
| */ | |
| private $serviceLocator; | |
| /** | |
| * @var Nette\Localization\ITranslator|Kdyby\Translation\Translator | |
| */ | |
| private $translator; | |
| public function __construct() | |
| { | |
| parent::__construct(); | |
| } | |
| public function injectContext(Nette\DI\Container $serviceLocator) | |
| { | |
| $this->serviceLocator = $serviceLocator; | |
| } | |
| /** | |
| * @return Nette\DI\Container|\SystemContainer | |
| */ | |
| protected function getServiceLocator() | |
| { | |
| if ($this->serviceLocator === NULL) { | |
| $this->serviceLocator = $this->getPresenter()->getContext(); | |
| } | |
| return $this->serviceLocator; | |
| } | |
| /** | |
| * @param string $class | |
| * @return Nette\Templating\FileTemplate|Nette\Templating\ITemplate|\stdClass | |
| */ | |
| protected function createTemplate($class = NULL) | |
| { | |
| $template = parent::createTemplate($class); | |
| /** @var \Nette\Templating\FileTemplate|\stdClass $template */ | |
| $sl = $this->getServiceLocator(); | |
| $template->consts = $this->presenter->template->consts; | |
| $template->productionMode = $sl->expand('%productionMode%'); | |
| foreach ($sl->findByTag('helperLoader') as $loader => $tags) { | |
| $template->registerHelperLoader(callback($sl->getService($loader), 'loader')); | |
| } | |
| return $template; | |
| } | |
| /** | |
| * @param \Nette\ComponentModel\Container $obj | |
| */ | |
| protected function attached($parent) | |
| { | |
| parent::attached($parent); | |
| $this->onAttached($this, $parent); | |
| } | |
| /** | |
| * @param \Kdyby\Translation\Translator|\Nette\Localization\ITranslator $translator | |
| * @return BaseControl | |
| */ | |
| public function setTranslator($translator) | |
| { | |
| $this->translator = $translator; | |
| } | |
| /** | |
| * @return \Kdyby\Translation\Translator|\Nette\Localization\ITranslator | |
| */ | |
| public function getTranslator() | |
| { | |
| if ($this->translator === NULL) { | |
| $this->translator = $this->getServiceLocator()->getByType('Nette\Localization\ITranslator'); | |
| } | |
| return $this->translator; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment