<commit_before><?php

/**
 * MvcCore
 *
 * This source file is subject to the BSD 3 License
 * For the full copyright and license information, please view
 * the LICENSE.md file that are distributed with this source code.
 *
 * @copyright	Copyright (c) 2016 <NAME> (https://github.com/mvccore/mvccore)
 * @license  https://mvccore.github.io/docs/mvccore/5.0.0/LICENCE.md
 */

namespace MvcCore\Config;

trait IniRead
{
	/**
	 * Load config file and return `TRUE` for success or `FALSE` in failure.
	 * - Second environment value setup:
	 *   - Only if `\MvcCore\Config::$system` property is defined as `TRUE`.
	 *   - By defined client IPs, server hostnames or environment variables 
	 *     in `environments` section. By values or regular expressions.
	 * - Load only sections for current environment name.
	 * - Retype all `raw string` values into `array`, `float`, `int` or `boolean` types.
	 * - Retype whole values level into `\stdClass`, if there are no numeric keys.
	 * @param string $fullPath
	 * @param bool $systemConfig
	 * @return bool
	 */
	public function Read ($fullPath, $systemConfig = FALSE) {
		if ($this->data) return $this->data;
		$this->fullPath = $fullPath;
		$this->system = $systemConfig;
		if (!$this->_iniScannerMode) 
			// 1 => INI_SCANNER_RAW, 2 => INI_SCANNER_TYPED
			$this->_iniScannerMode = version_compare(PHP_VERSION, '5.6.1', '<') ? 1 : 2;
		clearstatcache(TRUE, $fullPath);
		$this->lastChanged = filemtime($fullPath);
		$rawIniData = parse_ini_file(
			$this->fullPath, TRUE, $this->_iniScannerMode
		);
		if ($rawIniData === FALSE) return FALSE;
		$this->data = [];
		$envsSectionName = static::$environmentsSectionName;
		$environmentsData = NULL;
		if ($this->system && isset($rawIniData[$envsSectionName])) {
			$this->iniReadExpandLevelsAndReType(
				array_merge([], $rawIniData[$envsSectionName])
			);
			$environmentsData = array_merge([], $this->data);
			$environment = static::envDetectBySystemConfig($environmentsData);//production
			foreach ($this->objectTypes as & $objectType) 
				if ($objectType[0]) $objectType[1] = (object) $objectType[1];
			unset($rawIniData[$envsSectionName]);
			$this->data = [];
			$this->objectTypes = [];
		} else {
			$environment = static::$environment;
		}
		$iniData = $this->iniReadFilterEnvironmentSections($rawIniData, $environment);
		$this->iniReadExpandLevelsAndReType($iniData);<commit_msg>config - ini read bugfix<commit_after><?php

/**
 * MvcCore
 *
 * This source file is subject to the BSD 3 License
 * For the full copyright and license information, please view
 * the LICENSE.md file that are distributed with this source code.
 *
 * @copyright	Copyright (c) 2016 <NAME> (https://github.com/mvccore/mvccore)
 * @license  https://mvccore.github.io/docs/mvccore/5.0.0/LICENCE.md
 */

namespace MvcCore\Config;

trait IniRead
{
	/**
	 * Load config file and return `TRUE` for success or `FALSE` in failure.
	 * - Second environment value setup:
	 *   - Only if `\MvcCore\Config::$system` property is defined as `TRUE`.
	 *   - By defined client IPs, server hostnames or environment variables 
	 *     in `environments` section. By values or regular expressions.
	 * - Load only sections for current environment name.
	 * - Retype all `raw string` values into `array`, `float`, `int` or `boolean` types.
	 * - Retype whole values level into `\stdClass`, if there are no numeric keys.
	 * @param string $fullPath
	 * @param bool $systemConfig
	 * @return bool
	 */
	public function Read ($fullPath, $systemConfig = FALSE) {
		if ($this->data) return $this->data;
		$this->fullPath = $fullPath;
		$this->system = $systemConfig;
		if (!$this->_iniScannerMode) 
			// 1 => INI_SCANNER_RAW, 2 => INI_SCANNER_TYPED
			$this->_iniScannerMode = version_compare(PHP_VERSION, '5.6.1', '<') ? 1 : 2;
		clearstatcache(TRUE, $fullPath);
		$this->lastChanged = filemtime($fullPath);
		$rawIniData = parse_ini_file(
			$this->fullPath, TRUE, $this->_iniScannerMode
		);
		if ($rawIniData === FALSE) return FALSE;
		$this->data = [];
		$envsSectionName = static::$environmentsSectionName;
		$environmentsData = NULL;
		if ($this->system && isset($rawIniData[$envsSectionName])) {
			$rawIniEnvSectionData = array_merge([], $rawIniData[$envsSectionName]);
			$this->iniReadExpandLevelsAndReType($rawIniEnvSectionData);
			$environmentsData = array_merge([], $this->data);
			$environment = static::envDetectBySystemConfig($environmentsData);//production
			foreach ($this->objectTypes as & $objectType) 
				if ($objectType[0]) $objectType[1] = (object) $objectType[1];
			unset($rawIniData[$envsSectionName]);
			$this->data = [];
			$this->objectTypes = [];
		} else {
			$environment = static::$environment;
		}
		$iniData = $this->iniReadFilterEnvironmentSections($rawIniData, $environment);
		$this->iniReadExpandLevelsAndReType($iniData);
{'fraction_non_alphanumeric': 0.1439519469759735, 'fraction_numerical': 0.007456503728251864, 'mean_word_length': 4.324145534729879, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 45, 'https://': 4, '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': '4914356', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1547, 'n_words': 397}