HosipLan

Untitled

Feb 4th, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.91 KB | None | 0 0
  1.  
  2.  
  3. /**
  4.  * @method onAttached(BaseControl $control, Nette\Application\UI\PresenterComponent $parent)
  5.  * @method \BasePresenter getPresenter()
  6.  *
  7.  * @property \BasePresenter|BaseControl[] $presenter
  8.  * @property-read \BasePresenter|BaseControl[] $presenter
  9.  * @property \Nette\Templating\FileTemplate|\stdClass $template
  10.  * @property-read \Nette\Templating\FileTemplate|\stdClass $template
  11.  */
  12. class BaseControl extends Nette\Application\UI\Control
  13. {
  14.  
  15.     use AutowireComponentFactories;
  16.  
  17.     /**
  18.      * @var array of function (BaseControl $control, Nette\ComponentModel\Container $parent)
  19.      */
  20.     public $onAttached = array();
  21.  
  22.     /**
  23.      * @var Nette\DI\Container
  24.      */
  25.     private $serviceLocator;
  26.  
  27.     /**
  28.      * @var Nette\Localization\ITranslator|Translator
  29.      */
  30.     private $translator;
  31.  
  32.  
  33.  
  34.     public function __construct()
  35.     {
  36.         parent::__construct();
  37.     }
  38.  
  39.  
  40.  
  41.     public function injectContext(Nette\DI\Container $serviceLocator)
  42.     {
  43.         $this->serviceLocator = $serviceLocator;
  44.     }
  45.  
  46.  
  47.  
  48.     /**
  49.      * @return Nette\DI\Container|\SystemContainer
  50.      */
  51.     protected function getServiceLocator()
  52.     {
  53.         if ($this->serviceLocator === NULL) {
  54.             $this->serviceLocator = $this->getPresenter()->getContext();
  55.         }
  56.  
  57.         return $this->serviceLocator;
  58.     }
  59.  
  60.  
  61.  
  62.     /**
  63.      * @param \Nette\ComponentModel\Container $obj
  64.      */
  65.     protected function attached($parent)
  66.     {
  67.         parent::attached($parent);
  68.         $this->onAttached($this, $parent);
  69.     }
  70.  
  71.  
  72.  
  73.     /**
  74.      * @param \Kdyby\Translation\Translator|\Nette\Localization\ITranslator $translator
  75.      * @return BaseControl
  76.      */
  77.     public function setTranslator($translator)
  78.     {
  79.         $this->translator = $translator;
  80.     }
  81.  
  82.  
  83.  
  84.     /**
  85.      * @return \Kdyby\Translation\Translator|\Nette\Localization\ITranslator
  86.      */
  87.     public function getTranslator()
  88.     {
  89.         if ($this->translator === NULL) {
  90.             $this->translator = $this->getServiceLocator()->getByType('Nette\Localization\ITranslator');
  91.         }
  92.  
  93.         return $this->translator;
  94.     }
Advertisement
Add Comment
Please, Sign In to add comment