<commit_before><?php
namespace System\Core;

if (!defined('SYSTEM')) exit('No direct script access allowed');

/**
 * View class
 * 
 * @package		Kamele
 * @subpackage	System
 * @since		2.0
 * @author		<NAME> <<EMAIL>>
 */
class View {
	
	/**
	 * @var		string
	 */
	private $path;
	
	/**
	 * Constructor
	 * 
	 * @param	string	$path
	 * @return	void
	 */
	public function __construct($path) {
		if (file_exists($path) && is_file($path)) {
			$this->path = $path;
		} else {
			$this->path = null;
		}
	}
	
	/**
	 * Renders the view and returns it
	 * 
	 * @param	string[]	$data
	 * @return	string
	 */
	public function render($data) {
		return 	$this->ifelse(
					$this->fillInOutputs(
						$this->fillInViews(
							file_get_contents($this->path)
						), $data
					), $data
				);
		
	}
	
	/**
	 * Removes parts of the view that won't be needed (like false if statements)
	 * 
	 * @param 	string		$raw		The raw view to process
	 * @param	string[]	$data		The data to use while checking
	 * @return	string
	 */
	private function ifelse($raw, $data) {
		$layer = 0;
		$keepif = array();
		$from = array();
		$deleteparts = array();												// Formatted [ [from, to], [from, to] ]
		
		preg_match_all('/{{.*}}/', $raw, $matches, PREG_OFFSET_CAPTURE);		// Matches every {{something}} formatted tag
		//var_dump(json_encode($matches));
		//return $raw;
		foreach ($matches[0] as $tag) {
			$tagparts = explode(':', trim($tag[0], '{}'));								// Split the parts separated by a :
			switch ($tagparts[0]) {
				case 'if':
					$layer++;
					$keepif[$layer] = ($data[$tagparts[1]] == true);
					if (!$keepif[$layer]) {
						$from[$layer] = $tag[1];
					} else {
						$deleteparts[] = array($tag[1], $tag[1] + strlen($tag[0]));
						$from[$layer] = -1;
					}
					break;
				case 'else':
					if (!$keepif[$layer]) {
						$deleteparts[] = array($from[$layer], $tag[1] + strlen($tag[0]));<commit_msg>Deleted comments<commit_after><?php
namespace System\Core;

if (!defined('SYSTEM')) exit('No direct script access allowed');

/**
 * View class
 * 
 * @package		Kamele
 * @subpackage	System
 * @since		2.0
 * @author		<NAME> <<EMAIL>>
 */
class View {
	
	/**
	 * @var		string
	 */
	private $path;
	
	/**
	 * Constructor
	 * 
	 * @param	string	$path
	 * @return	void
	 */
	public function __construct($path) {
		if (file_exists($path) && is_file($path)) {
			$this->path = $path;
		} else {
			$this->path = null;
		}
	}
	
	/**
	 * Renders the view and returns it
	 * 
	 * @param	string[]	$data
	 * @return	string
	 */
	public function render($data) {
		return 	$this->ifelse(
					$this->fillInOutputs(
						$this->fillInViews(
							file_get_contents($this->path)
						), $data
					), $data
				);
		
	}
	
	/**
	 * Removes parts of the view that won't be needed (like false if statements)
	 * 
	 * @param 	string		$raw		The raw view to process
	 * @param	string[]	$data		The data to use while checking
	 * @return	string
	 */
	private function ifelse($raw, $data) {
		$layer = 0;
		$keepif = array();
		$from = array();
		$deleteparts = array();												// Formatted [ [from, to], [from, to] ]
		
		preg_match_all('/{{.*}}/', $raw, $matches, PREG_OFFSET_CAPTURE);		// Matches every {{something}} formatted tag
		foreach ($matches[0] as $tag) {
			$tagparts = explode(':', trim($tag[0], '{}'));								// Split the parts separated by a :
			switch ($tagparts[0]) {
				case 'if':
					$layer++;
					$keepif[$layer] = ($data[$tagparts[1]] == true);
					if (!$keepif[$layer]) {
						$from[$layer] = $tag[1];
					} else {
						$deleteparts[] = array($tag[1], $tag[1] + strlen($tag[0]));
						$from[$layer] = -1;
					}
					break;
				case 'else':
					if (!$keepif[$layer]) {
						$deleteparts[] = array($from[$layer], $tag[1] + strlen($tag[0]));
{'fraction_non_alphanumeric': 0.19123505976095617, 'fraction_numerical': 0.007436918990703851, 'mean_word_length': 2.739821251241311, 'pattern_counts': {'":': 0, '<': 11, '<?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': '2817200', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1328, 'n_words': 331}