<commit_before><?php

use store\Logger;
use handler\mode\AbstractModeHandler;
use store\Bucket;
use store\data\File;
use store\data\net\MAPUrl;

final class Web {

	const AUTOLOAD       = 'src/misc/autoload.php';
	const CONFIG_PUBLIC  = 'public/web.ini';
	const CONFIG_PRIVATE = 'private/web.ini';

	/**
	 * @var Bucket
	 */
	private $config;

	/**
	 * initialize application and load configs
	 */
	public function __construct() {
		include_once self::AUTOLOAD;

		if (!session_start()) {
			Logger::error('failed to start session');
			exit();
		}

		$this->config = new Bucket();
		# apply public config
		$this->config->applyIni(new File(self::CONFIG_PUBLIC));
		# apply private config
		$this->config->applyIni(new File(self::CONFIG_PRIVATE));
		# apply session config
		if (!isset($_SESSION['config'])) {
			$_SESSION['config'] = array();
		}
		$this->config->applyArray($_SESSION['config']);
	}

	/**
	 * call mode handler
	 *
	 * @throws Exception
	 * @return void
	 */
	public function main() {
		if (stripos($_SERVER['SERVER_PROTOCOL'], 'HTTPS') !== false) {
			$scheme = 'https';
		}
		else {
			$scheme = 'http';
		}

		$request      = new MAPUrl($scheme.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $this->config);
		$modeSettings = $this->config->get('mode', $request->getMode());

		if ($modeSettings === null) {
			throw new RuntimeException('mode `'.$request->getMode().'` not applied');
		}

		if (!class_exists($modeSettings['handler'])) {
			throw new RuntimeException('mode `'.$request->getMode().'` handler `'.$modeSettings['handler'].'` not applied');
		}

		$handler = new $modeSettings['handler']($this->config, $request, $modeSettings);
		if (!($handler instanceof AbstractModeHandler)) {
			throw new RuntimeException(
					'mode `'
					.$request->getMode()
					.'` handler `'
					.$modeSettings['handler']
					.'` is not instance of `handler\mode\AbstractModeHandler`'
			);
		}

		$handler->handle();
	}

}

(new Web())->main();<commit_msg>- fill constant ENVIRONMENT with 'DEV' or 'LIVE' (#24) - rewrite loading process of configs:<commit_after><?php

use store\Logger;
use handler\mode\AbstractModeHandler;
use store\Bucket;
use store\data\File;
use store\data\net\MAPUrl;

final class Web {

	const AUTOLOAD       = 'src/misc/autoload.php';
	const CONFIG_PUBLIC  = 'public/web.ini';
	const CONFIG_PRIVATE = 'private/web.ini';

	/**
	 * @var Bucket
	 */
	private $config;

	/**
	 * @var MAPUrl
	 */
	private $request;

	/**
	 * initialize application and load configs
	 */
	public function __construct() {
		include_once self::AUTOLOAD;

		if (strtolower(ini_get('display_errors')) === 'off') {
			define('ENVIRONMENT', 'LIVE');
		}
		else {
			define('ENVIRONMENT', 'DEV');
		}

		if (!session_start()) {
			Logger::error('failed to start session');
			exit();
		}

		# load public & private config
		$this->config = (new Bucket())
				->applyIni(new File(self::CONFIG_PUBLIC))
				->applyIni(new File(self::CONFIG_PRIVATE));

		# load MAPUrl
		if (stripos($_SERVER['SERVER_PROTOCOL'], 'HTTPS') !== false) {
			$scheme = 'https';
		}
		else {
			$scheme = 'http';
		}
		$this->request = new MAPUrl($scheme.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $this->config);

		# load area & page config
		$configPathList = array(
				'../private/src/area/'.$this->request->getArea().'/config/area.ini',
				'../private/src/area/'.$this->request->getArea().'/config/page/'.$this->request->getPage().'.ini'
		);
		foreach ($configPathList as $configPath) {
			$configFile = new File($configPath);
			if (!$configFile->isFile()) {
				if (constant('ENVIRONMENT') === 'DEV') {
					Logger::info('config-file `'.$configFile.'` not found');
				}
				continue;
			}
			$this->config->applyIni($configFile);
		}

		# load session config
		if (!isset($_SESSION['config'])) {
			$_SESSION['config'] = array();
		}
		$this->config->applyArray($_SESSION['config']);
	}

	/**
	 * call mode handler
	 *
	 * @throws Exception
	 * @return void
	 */
	public function main() {
		$modeSettings = $this->config->get('mode', $this->request->getMode());

		if ($modeSettings === null) {
			throw new RuntimeException('mode `'.$this->request->getMode().'` not applied');
		}

		if (!class_exists($modeSettings['handler'])) {
			throw new RuntimeException('mode `'.$this->request->getMode().'` is invalid');
		}

		$handler = new $modeSettings['handler']($this->config, $this->request, $modeSettings);
		if (!($handler instanceof AbstractModeHandler)) {
			throw new RuntimeException(
					'mode `'
					.$this->request->getMode()
					.'` handler `'
					.$modeSettings['handler']
					.'` is not instance of `handler\mode\AbstractModeHandler`'
			);
		}

		$handler->handle();
	}

}

(new Web())->main();
{'fraction_non_alphanumeric': 0.1933573090755236, 'fraction_numerical': 0.0004231013327691982, 'mean_word_length': 3.790273556231003, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 50, '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': '1821504', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1539, 'n_words': 316}