<commit_before><?php
/**
 * @author <NAME> <<EMAIL>>
 * @version 1.0
 */

namespace PSFS;

use PSFS\base\config\Config;
use PSFS\base\exception\ConfigException;
use PSFS\base\exception\RouterException;
use PSFS\base\exception\SecurityException;
use PSFS\base\Logger;
use PSFS\base\Singleton;

require_once __DIR__ . DIRECTORY_SEPARATOR . "bootstrap.php";

/**
 * Class Dispatcher
 * @package PSFS
 */
class Dispatcher extends Singleton
{
    /**
     * @Inyectable
     * @var \PSFS\base\Security $security
     */
    protected $security;
    /**
     * @Inyectable
     * @var \PSFS\base\Router $router
     */
    protected $router;
    /**
     * @Inyectable
     * @var \PSFS\base\Request $parser
     */
    protected $parser;
    /**
     * @Inyectable
     * @var \PSFS\base\Logger $log
     */
    protected $log;
    /**
     * @Inyectable
     * @var \PSFS\base\config\Config $config
     */
    protected $config;

    protected $ts;
    protected $mem;
    protected $locale = "es_ES";

    private $actualUri;

    /**
     * Initializer method
     */
    public function init()
    {
        Logger::log('Dispatcher init');
        parent::init();
        $this->initiateStats();
        $this->setLocale();
        $this->bindWarningAsExceptions();
        $this->actualUri = $this->parser->getServer("REQUEST_URI");
        Logger::log('End dispatcher init');
    }

    /**
     * Method that assign the locale to the request
     * @return $this
     */
    private function setLocale()
    {
        $this->locale = $this->config->get("default_language");
        Logger::log('Set locale to project [' . $this->locale . ']');
        // Load translations
        putenv("LC_ALL=" . $this->locale);
        setlocale(LC_ALL, $this->locale);
        // Load the locale path
        $locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale';
        Logger::log('Set locale dir ' . $locale_path);
        Config::createDir($locale_path);
        bindtextdomain('translations', $locale_path);
        textdomain('translations');
        bind_textdomain_codeset('translations', 'UTF-8');

        return $this;
    }

    /**
     * Run method
     * @return string HTML
     */
    public function run()
    {
        Logger::log('Begin runner');
        try {
            if ($this->config->isConfigured()) {
                if (!$this->parser->isFile()) {
                    return $this->router->execute($this->actualUri);
                }
            } else {
                return $this->router->getAdmin()->config();
            }
        } catch (ConfigException $c) {
            return $this->dumpException($c);
        } catch (SecurityException $s) {
            return $this->security->notAuthorized($this->actualUri);
        } catch (RouterException $r) {<commit_msg>Error on first installation workflow<commit_after><?php
/**
 * @author <NAME> <<EMAIL>>
 * @version 1.0
 */

namespace PSFS;

use PSFS\base\config\Config;
use PSFS\base\exception\ConfigException;
use PSFS\base\exception\RouterException;
use PSFS\base\exception\SecurityException;
use PSFS\base\Logger;
use PSFS\base\Singleton;
use PSFS\controller\ConfigController;

require_once __DIR__ . DIRECTORY_SEPARATOR . "bootstrap.php";

/**
 * Class Dispatcher
 * @package PSFS
 */
class Dispatcher extends Singleton
{
    /**
     * @Inyectable
     * @var \PSFS\base\Security $security
     */
    protected $security;
    /**
     * @Inyectable
     * @var \PSFS\base\Router $router
     */
    protected $router;
    /**
     * @Inyectable
     * @var \PSFS\base\Request $parser
     */
    protected $parser;
    /**
     * @Inyectable
     * @var \PSFS\base\Logger $log
     */
    protected $log;
    /**
     * @Inyectable
     * @var \PSFS\base\config\Config $config
     */
    protected $config;

    protected $ts;
    protected $mem;
    protected $locale = "es_ES";

    private $actualUri;

    /**
     * Initializer method
     */
    public function init()
    {
        Logger::log('Dispatcher init');
        parent::init();
        $this->initiateStats();
        $this->setLocale();
        $this->bindWarningAsExceptions();
        $this->actualUri = $this->parser->getServer("REQUEST_URI");
        Logger::log('End dispatcher init');
    }

    /**
     * Method that assign the locale to the request
     * @return $this
     */
    private function setLocale()
    {
        $this->locale = $this->config->get("default_language");
        Logger::log('Set locale to project [' . $this->locale . ']');
        // Load translations
        putenv("LC_ALL=" . $this->locale);
        setlocale(LC_ALL, $this->locale);
        // Load the locale path
        $locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale';
        Logger::log('Set locale dir ' . $locale_path);
        Config::createDir($locale_path);
        bindtextdomain('translations', $locale_path);
        textdomain('translations');
        bind_textdomain_codeset('translations', 'UTF-8');

        return $this;
    }

    /**
     * Run method
     * @return string HTML
     */
    public function run()
    {
        Logger::log('Begin runner');
        try {
            if ($this->config->isConfigured()) {
                if (!$this->parser->isFile()) {
                    return $this->router->execute($this->actualUri);
                }
            } else {
                return ConfigController::getInstance()->config();
            }
        } catch (ConfigException $c) {
            return $this->dumpException($c);
        } catch (SecurityException $s) {
            return $this->security->notAuthorized($this->actualUri);
        } catch (RouterException $r) {
{'fraction_non_alphanumeric': 0.146814893241574, 'fraction_numerical': 0.0010587612493382743, 'mean_word_length': 2.164712451144612, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 59, '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': '3348886', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1667, 'n_words': 338}