<commit_before><?php

/**
 * @author    <NAME> <<EMAIL>>
 * @package   Form
 * @link      https://github.com/juniwalk/form
 * @copyright <NAME> (c) 2016
 * @license   MIT License
 */

namespace JuniWalk\Form;

use Nette\Application\UI\Form;
use Nette\Application\UI\ITemplate;
use Nette\Localization\ITranslator;
use Nette\Utils\ArrayHash;

/**
 * @method void onBeforeRender(self $self, ITemplate $template)
 * @method void onSuccess(Form $form, ArrayHash $data)
 * @method void onError(Form $form)
 */
abstract class AbstractForm extends \Nette\Application\UI\Control
{
	/**
	 * @var FormFactory
	 */
	private $formFactory;

	/**
	 * @var string
	 */
	private $templateFile;

	/**
	 * @var callable[]
	 */
	public $onBeforeRender = [];

	/**
	 * @var callable[]
	 */
	public $onSuccess = [];

	/**
	 * @var callable[]
	 */
	public $onError = [];


	/**
	 * @param FormFactory $formFactory
	 */
	public function setFormFactory(FormFactory $formFactory)
	{
		$this->formFactory = $formFactory;
	}


	/**
	 * @return Form
	 */
	public function getForm() : Form
	{
		return $this->getComponent('form');
	}


	/**
	 * @return ITranslator
	 */
	public function getTranslator() : ITranslator
	{
		return $this->formFactory->getTranslator();
	}


	/**
	 * @param string|NULL  $file
	 */
	public function setTemplateFile(string $file = NULL)
	{
		$this->templateFile = $file;
	}


	public function render()
	{
		$template = $this->createTemplate();
		$template->setTranslator($this->getTranslator());
		$template->setFile(__DIR__.'/templates/form.latte');

		if ($this->templateFile) {
			$template->setFile($this->templateFile);
		}

		if (!empty($this->onBeforeRender)) {
			$this->onBeforeRender($this, $template);
		}

		$template->render();
	}


	/**
	 * @param  string  $name
	 * @return Form
	 */
	protected function createComponentForm(string $name) : Form
	{
		$form = $this->formFactory->create();
		$form->addProtection();<commit_msg>Set form to the template variable<commit_after><?php

/**
 * @author    <NAME> <<EMAIL>>
 * @package   Form
 * @link      https://github.com/juniwalk/form
 * @copyright <NAME> (c) 2016
 * @license   MIT License
 */

namespace JuniWalk\Form;

use Nette\Application\UI\Form;
use Nette\Application\UI\ITemplate;
use Nette\Localization\ITranslator;
use Nette\Utils\ArrayHash;

/**
 * @method void onBeforeRender(self $self, ITemplate $template)
 * @method void onSuccess(Form $form, ArrayHash $data)
 * @method void onError(Form $form)
 */
abstract class AbstractForm extends \Nette\Application\UI\Control
{
	/**
	 * @var FormFactory
	 */
	private $formFactory;

	/**
	 * @var string
	 */
	private $templateFile;

	/**
	 * @var callable[]
	 */
	public $onBeforeRender = [];

	/**
	 * @var callable[]
	 */
	public $onSuccess = [];

	/**
	 * @var callable[]
	 */
	public $onError = [];


	/**
	 * @param FormFactory $formFactory
	 */
	public function setFormFactory(FormFactory $formFactory)
	{
		$this->formFactory = $formFactory;
	}


	/**
	 * @return Form
	 */
	public function getForm() : Form
	{
		return $this->getComponent('form');
	}


	/**
	 * @return ITranslator
	 */
	public function getTranslator() : ITranslator
	{
		return $this->formFactory->getTranslator();
	}


	/**
	 * @param string|NULL  $file
	 */
	public function setTemplateFile(string $file = NULL)
	{
		$this->templateFile = $file;
	}


	public function render()
	{
		$template = $this->createTemplate();
		$template->setTranslator($this->getTranslator());
		$template->setFile(__DIR__.'/templates/form.latte');

		if ($this->templateFile) {
			$template->setFile($this->templateFile);
		}

		$template->add('form', $this->getForm());

		if (!empty($this->onBeforeRender)) {
			$this->onBeforeRender($this, $template);
		}

		$template->render();
	}


	/**
	 * @param  string  $name
	 * @return Form
	 */
	protected function createComponentForm(string $name) : Form
	{
		$form = $this->formFactory->create();
		$form->addProtection();
{'fraction_non_alphanumeric': 0.1700076122811469, 'fraction_numerical': 0.0020299416391778738, 'mean_word_length': 3.5890570430733413, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4471717', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1310, 'n_words': 264}