<commit_before><?php 

namespace Lighty\Kernel\Process;

use Lighty\Kernel\Process\Process;
use Lighty\Kernel\Objects\DateTime as Time;

/**
* View class
*/
class View
{
	protected static function replace($name)
	{
		return str_replace(":", "/", $name);
	}
	public static function create($name , $template, $rt= null)
	{
		switch ($template) {
			case 'smarty': $extention = ".tpl.php"; break;
			case 'atom': $extention = ".atom"; break;
			default: $extention = ".php"; break;
		}
		//
		$file	=	self::replace($name);
		$pos 	= 	strpos($file, "/");
		$Root = is_null($rt) ? Process::root : $rt ;
		if($pos)
		{
			$structure 	=   $Root."app/views/".$file[0]."/";
			//
			if(mkdir($structure, 0777, true)) 
			{
				$file		= 	explode("/", $file);
				return self::CreatView($file[1], $Root."app/views/".$file[0]."/", $extention);
			}
			else return 3;
		}
		else
		{
			return self::CreatView($file, $Root."app/views/", $extention);
		}

	}

	protected static function CreatView($file, $path, $ext)
	{
		if( ! file_exists($path."$file$ext"))
		{
			$myfile = fopen($path."$file$ext", "w");
			//
			$txt = self::set($ext , $file);
			//
			fwrite($myfile, $txt);
			fclose($myfile);
			//
			return 1;
		}
		else return 2;
	}

	protected static function set($ext , $file)
	{
		if($ext == '.atom') return "{// View file  : $file //} \n";
		elseif($ext == '.tpl.php') return "{* View file  : $file *} \n";
		else return "<?php\n\n/**\n* View file  : $file\n*/\n\n";
	}
}<commit_msg>fix bug of view creation<commit_after><?php 

namespace Lighty\Kernel\Process;

use Lighty\Kernel\Process\Process;
use Lighty\Kernel\Objects\DateTime as Time;
use Lighty\Kernel\Objects\Strings;

/**
* View class
*/
class View
{
	protected static function replace($name)
	{
		// return str_replace(":", "/", $name);
		return str_replace(".", "/", $name);
	}

	protected static function createFolders($folders, $root)
	{
		$path = $root."app/views/";
		//
		for ($i=0; $i < count($folders)-1 ; $i++)
		{
			$value = $folders[$i];
			//
			if(is_dir($path.$value))
				$path .= $value."/";
			else
			{
				$path .= $value."/";
				mkdir($path, 0777, true);
			}
		}
		//
		return array("path" => $path, "file" => $folders[count($folders)-1] );
	}

	public static function create($name , $template, $rt= null)
	{
		switch ($template) {
			case 'smarty': $extention = ".tpl.php"; break;
			case 'atom': $extention = ".atom"; break;
			default: $extention = ".php"; break;
		}
		//
		$Root = is_null($rt) ? Process::root : $rt ;
		$file	=	self::replace($name);
		$folders = Strings::splite($file,"/");
		//
		$file = self::createFolders($folders, $Root);
		//
		return self::CreatView($file["file"], $file["path"], $extention);
	}

	protected static function CreatView($file, $path, $ext)
	{
		if( ! file_exists($path."$file$ext"))
		{
			$myfile = fopen($path."$file$ext", "w");
			//
			$txt = self::set($ext , $file);
			//
			fwrite($myfile, $txt);
			fclose($myfile);
			//
			return 1;
		}
		else return 2;
	}

	protected static function set($ext , $file)
	{
		if($ext == '.atom') return "{// View file  : $file //} \n";
		elseif($ext == '.tpl.php') return "{* View file  : $file *} \n";
		else return "<?php\n\n/**\n* View file  : $file\n*/\n\n";
	}
}
{'fraction_non_alphanumeric': 0.22466007416563658, 'fraction_numerical': 0.0058714462299134735, 'mean_word_length': 3.092288242730721, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 5, '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': '4190178', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1244, 'n_words': 261}