<?php
/**
* 設定に関するユーティリティクラス
*
* PHP version 5
*
* @package    core
* @author     stk2k <stk2k@sazysoft.com>
* @copyright  2008 stk2k, sazysoft
*/

class ConfigUtil
{
	static $macro_defs;

	/*
	 * マクロ展開
	 */
	public static function processMacro( String $value )
	{
		// 展開キーワード
		if ( self::$macro_defs === NULL ){
			self::$macro_defs = array(

					'%CONFIG_DIR%'       => ResourceLocator::getWebAppPath( s('config') ),
					'%COMPONENTS_DIR%'   => ResourceLocator::getWebAppPath( s('components') ),
					'%LOGS_DIR%'         => ResourceLocator::getWebAppPath( s('logs') ),
					'%TEMPLATES_DIR%'    => ResourceLocator::getWebAppPath( s('templates') ),
					'%WEBAPP_DIR%'       => WEBAPP_DIR . '/' . APPLICATION,
					'%CHARCOAL_HOME%'    => CHARCOAL_HOME,

				);
		}

		// 展開
		if ( strpos("$value",'%') !== FALSE ){
			foreach( self::$macro_defs as $macro_key => $macro_value ){
				if ( strpos("$value",$macro_key) !== FALSE ){
					$value = s( str_replace( $macro_key, $macro_value, "$value" ) );
				}
			}
		}

		return $value;
	}
}

return __FILE__;