<commit_before><?php

namespace Gelembjuk\WebApp;

use \Gelembjuk\WebApp\Exceptions\ViewException as ViewException;
use \Gelembjuk\WebApp\Exceptions\DoException as DoException;

abstract class Controller {
	use \Gelembjuk\Logger\ApplicationLogger;
	use \Gelembjuk\Locale\GetTextTrait;
	
	protected $router;
	protected $responseformat;
	protected $actionerrordisplay = 'redirect';
	protected $application;
	protected $defmodelname;
	protected $defmodel;
	protected $defviewname = '';
	protected $viewdata;
	protected $signinreqired;
	
	public function __construct($application,$router = null) {
		$this->application = $application;
		$this->router = $router;
		
		$this->viewdata = array();
		
		if (!$this->router) {
			$this->router = $this->getRouter();
		}
		
		if ($this->defmodelname != '') {
			$this->defmodel = $this->application->getModel($this->defmodelname);
		}
		
		$this->signinreqired = false;
	}
	public function init() {
	}
	public function action() {
		$this->application->setActionController($this);
		
		$this->initAuthSession();
		
		list($actiontype,$actionmethod,$this->responseformat) = $this->router->getActionInfo();
		
		$this->beforeStart();
		
		// set response format to error handler. so if error happens 
		// after this place then reponse is in correct format
		$errorhandler = $this->application->getErrorHandler();
		
		if (is_object($errorhandler)) {
			$errorhandler->setViewFormat( ($this->responseformat != '') ? $this->responseformat:'html' );
		}
		
		if ($actiontype == 'do') {
			$methodname = 'do'.$actionmethod;
			
			if( method_exists($this,$methodname) ) {<commit_msg>Allow exceptions in before start function<commit_after><?php

namespace Gelembjuk\WebApp;

use \Gelembjuk\WebApp\Exceptions\ViewException as ViewException;
use \Gelembjuk\WebApp\Exceptions\DoException as DoException;

abstract class Controller {
	use \Gelembjuk\Logger\ApplicationLogger;
	use \Gelembjuk\Locale\GetTextTrait;
	
	protected $router;
	protected $responseformat;
	protected $actionerrordisplay = 'redirect';
	protected $application;
	protected $defmodelname;
	protected $defmodel;
	protected $defviewname = '';
	protected $viewdata;
	protected $signinreqired;
	
	public function __construct($application,$router = null) {
		$this->application = $application;
		$this->router = $router;
		
		$this->viewdata = array();
		
		if (!$this->router) {
			$this->router = $this->getRouter();
		}
		
		if ($this->defmodelname != '') {
			$this->defmodel = $this->application->getModel($this->defmodelname);
		}
		
		$this->signinreqired = false;
	}
	public function init() {
	}
	public function action() {
		$this->application->setActionController($this);
		
		$this->initAuthSession();
		
		list($actiontype,$actionmethod,$this->responseformat) = $this->router->getActionInfo();
		
		try {
            $this->beforeStart();
		} catch(\Exception $e) {
            $actiontype = 'view';
            $actionmethod = 'error';
            
            $this->router->setInput('errormessage',$e->getMessage());
            $this->router->setInput('errornumber',$e->getCode());
		}
		
		// set response format to error handler. so if error happens 
		// after this place then reponse is in correct format
		$errorhandler = $this->application->getErrorHandler();
		
		if (is_object($errorhandler)) {
			$errorhandler->setViewFormat( ($this->responseformat != '') ? $this->responseformat:'html' );
		}
		
		if ($actiontype == 'do') {
			$methodname = 'do'.$actionmethod;
			
			if( method_exists($this,$methodname) ) {
{'fraction_non_alphanumeric': 0.14961745536979315, 'fraction_numerical': 0.0, 'mean_word_length': 4.138282387190684, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '5155138', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1068, 'n_words': 216}