<commit_before><?php 

/* **************************************

Sahayak
=======
The Command Line Tool for Blazing

Load the module
*****************************************/

require_once "application/sahayak/load.php";<commit_msg>CLI for route and controller insertion<commit_after><?php 
/***************************************
Sahayak 2.0

The Command Line Tool for Blazing
*****************************************/
$slug           = explode('/', $argv[2]);
$controller     = $argv['1'];
$method         = "";
$parameterList  = [];
$routeLine     = PHP_EOL."Route::"; 
$controllerLine = PHP_EOL;

// if post request
if($argc == 4){
    $routeLine.= "post('";
}else{
    $routeLine.= "set('";
}

// get param list and method
foreach($slug as $node){
    if(strpos($node, '$') !== false){
        array_push($parameterList,$node);
    }
    else{
        $method.=ucwords($node);
    }
}

/// line to add to routes
$routeLine.=$argv[2].'\',\''.$controller.'@'.$method.'\');';


// CONTROLLER DATA
$controllerLine .= "function ".$method."(\$url){".PHP_EOL;
foreach($parameterList as $node){
    $controllerLine.= "\t".$node." = \$url['".$node."'];".PHP_EOL;
}
$controllerLine.= PHP_EOL."}";


// Writing route
$handle = file_get_contents("application/modules/routes.php");
file_put_contents("application/modules/routes.php",$handle.$routeLine);

// writing controller
if(!file_exists("application/modules/controller/".$controller.".controller.php")){
    $handle = fopen("application/modules/controller/".$controller.".controller.php","w");
    fclose($handle);
    $controllerLine = "<?php ".PHP_EOL.PHP_EOL.$controllerLine.PHP_EOL;
}

$handle = file_get_contents("application/modules/controller/".$controller.".controller.php");
file_put_contents("application/modules/controller/".$controller.".controller.php",$handle.$controllerLine);
{'fraction_non_alphanumeric': 0.2725298588490771, 'fraction_numerical': 0.003257328990228013, 'mean_word_length': 4.741433021806854, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, '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': '2297414', 'n_tokens_mistral': 581, 'n_tokens_neox': 568, 'n_words': 96}