/ Gists / MatchResult component
On gists

MatchResult component

Nette Nette-Controls PHP

MatchResultControl.php Raw #

<?php


class MatchResult extends Control{

	const TEMPLATE_FULL = 'full';
	const TEMPLATE_INLINE = 'inline';

	public function renderFull($match){
		$this->render($match, self::TEMPLATE_FULL);
	}

	public function renderInline($match){
		$this->render($match, self::TEMPLATE_INLINE);
	}

	private function render($match, $templateName){
		$template = $this->createTemplate();
		$template->setFile(__DIR__.'/'.$templateName.'.latte');
		$template->match = $this->evaluateResult($match);
		$template->render();
	}

	private function evaluateResult($match){
		return //...
	}
}

MatchResultControl.php Raw #

<?php


class MatchResult extends Control{

	const TEMPLATE_FULL = 'full';
	const TEMPLATE_INLINE = 'inline';

	public function renderFull($match){
		$this->render($match, self::TEMPLATE_FULL);
	}

	public function renderInline($match){
		$this->render($match, self::TEMPLATE_INLINE);
	}

	private function render($match, $templateName){
		$template = $this->createTemplate();
		$template->setFile(__DIR__.'/'.$templateName.'.latte');
		$template->match = $this->evaluateResult($match);
		$template->render();
	}

	private function evaluateResult($match){
		return //...
	}
}

MatchResultFactory.php Raw #

<?php

interface MatchResultFactory{
	/** @return MatchResult */
	public function create();
}

MatchResultFactory.php Raw #

<?php

interface MatchResultFactory{
	/** @return MatchResult */
	public function create();
}

config.neon Raw #

matchResult:
		class: MatchResult
		implement: MatchResultFactory

Presenter.php Raw #

<?php

/** @var \MatchResultFactory @inject */
public $matchResultFactory;

protected function createComponentMatchResult(){
	return $this->matchResultFactory->create();
}

Presenter.php Raw #

<?php

/** @var \MatchResultFactory @inject */
public $matchResultFactory;

protected function createComponentMatchResult(){
	return $this->matchResultFactory->create();
}

config.neon Raw #

matchResult:
		class: MatchResult
		implement: MatchResultFactory

results.latte Raw #

{foreach $matches as $match}

	{control matchResult:full, $match}
	{control matchResult:inline, $match}

{/foreach}

results.latte Raw #

{foreach $matches as $match}

	{control matchResult:full, $match}
	{control matchResult:inline, $match}

{/foreach}