Skip to content

Instantly share code, notes, and snippets.

@duskohu
Last active December 29, 2015 02:19
Show Gist options
  • Save duskohu/7599787 to your computer and use it in GitHub Desktop.
Save duskohu/7599787 to your computer and use it in GitHub Desktop.
Priklad Inject TestControl extends BaseControl
<?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;
}
}
factories:
- \App\ITestControl
<?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;
}
}
<?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