<commit_before><?php

namespace WernerDweight\Microbe\framework\controller;

use WernerDweight\Microbe\framework\kernel\Kernel;
use WernerDweight\Microbe\framework\router\exception\PageNotFoundException;
use WernerDweight\Microbe\framework\router\exception\BadRequestException;
use WernerDweight\Microbe\framework\router\exception\UnauthorizedException;

abstract class AbstractController{
	
	protected $context;
	protected $kernel;

	public function __construct(Kernel $kernel, $contentType = 'html'){
		$this->kernel = $kernel;
		$this->context = array(
			'vars' => array(),
		);
		$this->kernel->service('twig')->addGlobal('g_current_route',$this->kernel->service('router')->getCurrentRoute());
		$this->kernel->service('twig')->addGlobal('g_current_route_name',$this->kernel->service('router')->getCurrentRouteName());
		$this->initialize();
	}

	protected function setHeaders($string,$replace = true,$responseCode = 200){
		header($string,$replace,$responseCode);
	}

	protected function validateRequest(){}

	protected function initialize(){}

	protected function finalize(){}

	/// twig

	protected function setTwigVar($key,$value){
		$this->context['vars'][$key] = $value;
	}

	/// dobee

	protected function getDobeeProvider(){
		return $this->kernel->service('dobee')->getProvider();
	}

	/// router

	protected function renderWithVars($template){
		$this->finalize();
		return $this->kernel->service('twig')->render($template,$this->context['vars']);
	}

	protected function redirect($url,$statusCode = 303){
		return $this->kernel->service('router')->redirect($url,$statusCode);
	}

	protected function redirectToRoute($routeName,$options = [],$statusCode = 303){
		return $this->redirect(
			$this->kernel->service('router')->path(
				$routeName,<commit_msg>Added controller to controller forwarding support<commit_after><?php

namespace WernerDweight\Microbe\framework\controller;

use WernerDweight\Microbe\framework\kernel\Kernel;
use WernerDweight\Microbe\framework\router\exception\PageNotFoundException;
use WernerDweight\Microbe\framework\router\exception\BadRequestException;
use WernerDweight\Microbe\framework\router\exception\UnauthorizedException;

abstract class AbstractController{
	
	protected $context;
	protected $kernel;

	public function __construct(Kernel $kernel, $contentType = 'html'){
		$this->kernel = $kernel;
		$this->context = array(
			'vars' => array(),
		);
		$this->kernel->service('twig')->addGlobal('g_current_route',$this->kernel->service('router')->getCurrentRoute());
		$this->kernel->service('twig')->addGlobal('g_current_route_name',$this->kernel->service('router')->getCurrentRouteName());
		$this->initialize();
	}

	protected function setHeaders($string,$replace = true,$responseCode = 200){
		header($string,$replace,$responseCode);
	}

	protected function validateRequest(){}

	protected function initialize(){}

	protected function finalize(){}

	/// twig

	protected function setTwigVar($key,$value){
		$this->context['vars'][$key] = $value;
	}

	/// dobee

	protected function getDobeeProvider(){
		return $this->kernel->service('dobee')->getProvider();
	}

	/// router

	protected function renderWithVars($template){
		$this->finalize();
		return $this->kernel->service('twig')->render($template,$this->context['vars']);
	}

	protected function forward($controller,$action,$options = []){
		return $this->kernel->service('router')->render($controller,$action,$options);
	}

	protected function redirect($url,$statusCode = 303){
		return $this->kernel->service('router')->redirect($url,$statusCode);
	}

	protected function redirectToRoute($routeName,$options = [],$statusCode = 303){
		return $this->redirect(
			$this->kernel->service('router')->path(
				$routeName,
{'fraction_non_alphanumeric': 0.16912355936746182, 'fraction_numerical': 0.004824443848834093, 'mean_word_length': 6.493975903614458, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 70, 'https://': 0, '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': '6804921', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1050, 'n_words': 173}