Last active
December 29, 2015 02:19
-
-
Save duskohu/7599787 to your computer and use it in GitHub Desktop.
Priklad Inject TestControl extends BaseControl
This file contains 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 | |
namespace App; | |
use NasExt\Templating\ITemplateFilesFormatter; | |
use Nette\Application\UI\Control; | |
use Nette\Templating\ITemplate; | |
class BaseControl extends Control | |
{ | |
/** | |
* Nejaka sluzba ktora najde sablonu pre control | |
* @var ITemplateFilesFormatter | |
*/ | |
protected $templateFilesFormatter; | |
/** | |
* INJECT TemplateFilesFormatter | |
* @param ITemplateFilesFormatter $templateFilesFormatter | |
*/ | |
public function injectTemplateFilesFormatter(ITemplateFilesFormatter $templateFilesFormatter) | |
{ | |
$this->templateFilesFormatter = $templateFilesFormatter; | |
} | |
/** | |
* @param string|NULL | |
* @return ITemplate | |
*/ | |
protected function createTemplate($class = NULL) | |
{ | |
$template = parent::createTemplate($class); | |
$template->setFile($this->templateFilesFormatter(....)); | |
return $template; | |
} | |
} |
This file contains 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
factories: | |
- \App\ITestControl |
This file contains 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 | |
namespace App; | |
class TestPresenter extends Presenter | |
{ | |
/** @var ITestControl */ | |
private $testControl; | |
/** | |
* INJECT TestControl | |
* @param ITestControl $testControl | |
*/ | |
public function injectTestControl(ITestControl $testControl) | |
{ | |
$this->testControl = $testControl; | |
} | |
/** | |
* @return TestControl | |
*/ | |
protected function createComponentTest() | |
{ | |
$control = $this->testControl->create(); | |
return $control; | |
} | |
} |
This file contains 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 | |
namespace App; | |
class TestControl extends BaseControl | |
{ | |
/** @var MyRepository */ | |
private $myRepository; | |
/** | |
* @param MyRepository $myRepository | |
*/ | |
public function __construct(MyRepository $myRepository) | |
{ | |
$this->myRepository = $myRepository; | |
} | |
public function render() | |
{ | |
$this->template->myRepository = $this->myRepository; | |
$this->template->render(); | |
} | |
} | |
/** | |
* ITestControl | |
*/ | |
interface ITestControl | |
{ | |
/** | |
* @return TestControl | |
*/ | |
public function create(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment