Example #1
0
 	/** 
 	 * Loads a specific environment, or the default one specified in the .conf
 	 * 
 	 * @param string $env The environment to load
 	 */
 	public static function LoadEnvironment($env=null)
 	{
 		$config=Config::Get('environment');
 		
 		if ($env==null)
 			$env=$config->environment;
 			
 		if($config->environment instanceof Config)
 		{
 			foreach($config->environment->items as $key=>$item)
 			{	
 				if (strtolower($_SERVER['SERVER_NAME'])==strtolower($key))
 				{
 					$env=$item;
 					break;
 				}
 			}
 		}
 		
		self::$environment=$env;
		
 		if ($config->{$env}!=null)
 		{
 			self::$environment_config=$config->{$env};
 			
 			// if in debug, load the developer's custom environment and merge it.
 			if ($env=='debug')
			{
				try
				{
					$your_config=Config::Get('environment.user');
					
					foreach($your_config->items as $key=>$custom)
						if (isset(self::$environment_config->items[$key]))
							foreach($custom->items as $k => $v)
								self::$environment_config->items[$key]->items[$k]=$v;
						else
							self::$environment_config->items[$key]=$custom;
				} 
				catch (Exception $ex)
				{
					// do nothing, means your_environment doesn't exist.	
				}
			}
			
 			if (self::$environment_config->defines!=null)
 				foreach(self::$environment_config->defines->items as $key => $value)
 				{
 					define($key,$value);
 				}

 			if (self::$environment_config->uses!=null)
 				foreach(self::$environment_config->uses->before->items as $item)
 					uses($item);
 					
 			if (self::$environment_config->config_map!=null)
 				self::$_config_map=self::$environment_config->config_map->items;
 					
 			define('ENVIRONMENT',$env);
 		}
 	}