<commit_before><?php
require_once 'NpModel.php';
require_once 'NpView.php';

class NpController
{
	protected function terminate($message=null)
	{
		if(empty($message))
			throw new NpExitException();
		else
			throw new NpCoreException($message);
	}

	protected function beforeProcess($action)
	{
	}

	protected function afterProcess()
	{
	}

	protected function onModelTerminate($code)
	{
		$this->terminate('Not implement modelTerminate, code='.$code);
	}

	private function invokeAction($action)
	{
		$result=null;
		$this->beforeProcess($action);
		try {
			$result=$this->$action();
			$this->afterProcess();
		} catch(NpModelException $e) {
			$this->onModelTerminate($e->getCode());
		}
		return $result;
	}
	
	public static function execute($module, $action)
	{
		$moduleFile = NP_APP_PATH."controller/".$module.".php";
		if(!file_exists($moduleFile))
			throw new NpCoreException('No module: '.$module);
		require_once($moduleFile);
		$controller=new $module();
		if(!method_exists($controller,$action))
			throw new NpCoreException('No action: '.$action.' in module: '.$module);
		return $controller->invokeAction($action);
	}

}
?><commit_msg>add: onActionComplete for NpController<commit_after><?php
require_once 'NpModel.php';
require_once 'NpView.php';

class NpController
{
	protected function terminate($message=null)
	{
		if(empty($message))
			throw new NpExitException();
		else
			throw new NpCoreException($message);
	}

	protected function beforeProcess($action)
	{
	}

	protected function afterProcess()
	{
	}

	protected function onModelTerminate($code)
	{
		$this->terminate('Not implement modelTerminate, code='.$code);
	}
	
	protected function onActionComplete()
	{
	}

	private function invokeAction($action)
	{
		$result=null;
		try
		{
			$this->beforeProcess($action);
			try {
				$result=$this->$action();
				$this->afterProcess();
			} catch(NpModelException $e) {
				$this->onModelTerminate($e->getCode());
			}
		} catch(Exception $e) {
			$this->onActionComplete();
			throw $e;
		}
		$this->onActionComplete();
		return $result;
	}
	
	public static function execute($module, $action)
	{
		$moduleFile = NP_APP_PATH."controller/".$module.".php";
		if(!file_exists($moduleFile))
			throw new NpCoreException('No module: '.$module);
		require_once($moduleFile);
		$controller=new $module();
		if(!method_exists($controller,$action))
			throw new NpCoreException('No action: '.$action.' in module: '.$module);
		return $controller->invokeAction($action);
	}

}
?>
{'fraction_non_alphanumeric': 0.15165511932255582, 'fraction_numerical': 0.0, 'mean_word_length': 3.9884836852207295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '6174132', 'n_tokens_mistral': 932, 'n_tokens_neox': 830, 'n_words': 155}