<commit_before><?php

/**
 * Walrus Framework
 * File maintened by: <NAME> (E-Wok)
 * Created: 16:10 13/12/13
 */

namespace Walrus\core;

use Exception;

class WalrusKernel
{

    public static function execute()
    {
        //self::bootstrap();
        try {
            $WalrusRoute = WalrusRouter::getInstance();
            $WalrusRoute->execute();
        } catch (Exception $e) {
            // @TODO: add Exception
        }


    }

    private static function bootstrap()
    {
        $config_file = "../config/config.yml";

        if (file_exists($config_file)) {

            $array_info = \Spyc::YAMLLoad($config_file);
            // \Spyc::YAMLDump($array, 4, 60)

            if ($array_info['templating']['default'] == 'haml') {
                //installer haml
            } elseif ($array_info['templating']['default'] == 'smarty') {
                //installer smarty
            } else {
                //installer twig
            }

            if ($array_info['database']['language'] == 'MySQL') {
                //installer MySQL
                $dbname = $array_info['database']['name'];
                $dbpwd = $array_info['database']['password'];
            } else {
                // autre db ?
            }
        } else {
            $php_content = array(
		"configfile" => array("language" => "yml"),  // to deal with
                "database" => array("language" => "MySQL",
                                    "name" => "project",
                                    "password" => ""),
                "templating" => array("default" => "haml")
            );

            $yml_content = \Spyc::YAMLDump($php_content);

            file_put_contents($config_file, $yml_content, FILE_APPEND);
        }

        //configuration here
    }
}<commit_msg>Tests done in config<commit_after><?php

/**
 * Walrus Framework
 * File maintened by: <NAME> (E-Wok)
 * Created: 16:10 13/12/13
 */

namespace Walrus\core;

use Exception;

class WalrusKernel
{

    public static function execute()
    {
        //self::bootstrap();
        try {
            $WalrusRoute = WalrusRouter::getInstance();
            $WalrusRoute->execute();
        } catch (Exception $e) {
            // @TODO: add Exception
        }


    }

    private static function bootstrap()
    {
        $config_file = "../config/config.yml";

        if (file_exists($config_file)) {

            $array_info = \Spyc::YAMLLoad($config_file);
            // \Spyc::YAMLDump($array, 4, 60)
	    $error = false;
	    $errorArray = array();
	    $WalrusConfig = array();

            if (strcasecmp($array_info['templating'], 'HAML') == 0 || strcasecmp($array_info['templating'], 'Twig') == 0 || strcasecmp($array_info['templating'], 'Smarty') == 0) {
	      $WalrusConfig['templating'] = $array_info['templating'];
            } else {
	      $error = true;
	      $errorArray['templating'] = "Templating must be HAML, Twig or Smarty";
            }

            if (strcasecmp($array_info['database']['language'], 'MySQL') == 0 || strcasecmp($array_info['database']['language'], 'SQLite') == 0 || strcasecmp($array_info['database']['language'], 'PostgreSQL') == 0 || strcasecmp($array_info['database']['language'], 'Oracle') == 0) {
	      $WalrusConfig['dbLanguage'] = $array_info['database']['language'];
            } else {
	      $error = true;
	      $errorArray['dbLanguage'] = "Database must be either MySQL, SQLite, PostgreSQL or Oracle";
            }

            if ($array_info['database']['host'] != "") {
	      $WalrusConfig['dbHost'] = $array_info['database']['host'];
            } else {
	      $error = true;
	      $errorArray['dbHost'] = "Database host can't be empty (IP address)";
            }

            if ($array_info['database']['name'] != "") {
	      $WalrusConfig['dbName'] = $array_info['database']['name'];
            } else {
	      $error = true;
	      $errorArray['dbName'] = "Database name can't be empty";
            }

            if (strcasecmp($array_info['environment'], 'dev') == 0 || strcasecmp($array_info['environment'], 'prod') == 0) {
	      $WalrusConfig['environment'] = $array_info['environment'];
            } else {
	      $error = true;
	      $errorArray['environment'] = "Environment must be dev or prod";
            }

	    if ($error == true) {
	      throw new Exception($errorArray);
	    }

	    $GLOBALS['WalrusConfig']= $WalrusConfig;
	    $GLOBALS['errorConfig']= $errorArray;

        } else {
	  $info_content = "#Please feed those information : \n #database can be MySQL | SQLite | PostgreSQL | Oracle \n #templating can be HAML | Twig | Smarty \n #environment can be dev or prod \n #config and routing are yml files \n \n";
	  $php_content = array(
			       "database" => array("language" => "",
						   "host" => "",
						   "name" => "",
						   "password" => ""),
			       "templating" => "",
			       "environment" => ""                // dev or prod
			       );
	  
	  $yml_content = \Spyc::YAMLDump($php_content);
	  
	  file_put_contents($config_file, $info_content.$yml_content, FILE_APPEND);
        }
    }
}
{'fraction_non_alphanumeric': 0.16477495107632095, 'fraction_numerical': 0.00684931506849315, 'mean_word_length': 2.075210589651023, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '637267', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1482, 'n_words': 311}