Esempio n. 1
0
	/**
	 * ...
	 * 
	 * @param 	array 	$cnfSections
	 * @param 	bool	$overwrite
	 */
	static private function mergeSectionedConfigData($cnfSections, $overwrite = true)
	{
		if (!is_array($cnfSections))
			return;

		$replacement 	= array();	
		$search			= array();
		$replace		= array();
		
		foreach ($cnfSections as $key => $section)
		{
			if($key == 'import') {
				foreach($section as $imports)
					foreach($imports as $importFile)
						if($importFile = SymfonyApp::getRootDir() .'/'. $importFile)
							if(file_exists($importFile))
								$replacement = array_merge($replacement, parse_ini_file($importFile, true));
											
				foreach($replacement as $k => $v) {
					$search[] 	= "%{$k}%";					
					$replace[] 	= $v;
				}
			}
			else 
			{				
				// do the replacements from the import
				$section = self::parseConfigReplacements($section, $search, $replace);
				
				if (is_array($section)) { 
					// an actual section - so concatenate
					self::$config = $overwrite ? array_merge(self::$config, $section) : array_merge($section, self::$config);
					
					if (!isset(self::$config_section[ $key ])) {
						self::$config_section[ $key ] = $section;
					} else {
						self::$config_section[ $key ] = $overwrite	? array_merge(self::$config_section[ $key ], $section)
																	: array_merge($section, self::$config_section[ $key ])
																	;
					}
					
					
				} else if (!is_numeric($key) && is_scalar($section)) {
					// an ini setting (that falls outside any section) - add to array an remove from sectionsd
					if ($overwrite || !isset(self::$config[$key]))				
						self::$config[$key] = $section;				
				}
			}
		}	
	}
	/**
	 * ...
	 * 
	 * @param 	array 	$cnfSections
	 * @param 	bool	$overwrite
	 */
	static private function mergeSectionedConfigData($cnfSections, $overwrite = true)
	{
		if (!is_array($cnfSections))
			return;

		$replacement 	= array();	
		$search			= array();
		$replace		= array();
		
		if (isset($cnfSections['import'])) {
			foreach ($cnfSections['import'] as $imports) {
				foreach ($imports as $importFile) {
					if ($importFile = SymfonyApp::getRootDir() .'/'. $importFile) {
						if (file_exists($importFile)) {
							self::mergeSectionedConfigData( parse_ini_file($importFile, true) );
						}
					}
				}
			}
		}
		
		foreach ($cnfSections as $key => $section) {
			if ($key == 'import') {
				continue;
			}
			
			// an actual section - so concatenate
			if (is_array($section)) { 
				self::$config = $overwrite ? array_merge(self::$config, $section) : array_merge($section, self::$config);
				
				$keys = array_keys($section);
				
				if (!isset(self::$section_keys[ $key ])) {
					self::$section_keys[ $key ] = $keys;
				} else {
					self::$section_keys[ $key ] = $overwrite	? array_merge(self::$section_keys[ $key ], $keys)
																: array_merge($keys, self::$section_keys[ $key ])
																;
				}
				
			// an ini setting (that falls outside any section) - add to array
			} else if (!is_numeric($key) && is_scalar($section)) {
				if ($overwrite || !isset(self::$config[$key])) {			
					self::$config[$key] = $section;				
				}
			}
		}
	}