Zend_Configの値の置換

構成ファイルで値の置換を使用する必要が生じた場合、 公式ドキュメントは、ベストプラクティスではないIMHOの使用を明確に示唆しています。たとえば、INIファイルでの定数の使用は次のようになります。



[production]

includePaths.library = APPLICATION_PATH "/../library"

bootstrap.path = APPLICATION_PATH "/Bootstrap.php"








Zend_Configの機能を継承および拡張する小さなクラスを作成し、次の構文を使用できるようにしました。



[production]

path.application = "${path.root}/application"

path.configs = "${path.application}/configs"

includePaths.library = "${path.root}/library"










以下にその使用例を示します。

//

$environment = 'production' ;



//

$rootPath = dirname(__FILE__);



//

$configPath = rootPath . '/application/configs/application.ini' ;



// ""

// read-only

$configRaw = new Zend_Config_Ini($configPath, $environment, true );



//

$configRaw->path->root = $rootPath;



// , "" ""

$config = Inf_Config_Placeholder($configRaw);



// ,



* This source code was highlighted with Source Code Highlighter .


, :

[production]

foo = "${bar}"

bar = "${foo}"








, , 7 .



Inf_Config_Placeholder GitHub .



PS GitHub' - , library . , - ?








//

$environment = 'production' ;



//

$rootPath = dirname(__FILE__);



//

$configPath = rootPath . '/application/configs/application.ini' ;



// ""

// read-only

$configRaw = new Zend_Config_Ini($configPath, $environment, true );



//

$configRaw->path->root = $rootPath;



// , "" ""

$config = Inf_Config_Placeholder($configRaw);



// ,



* This source code was highlighted with Source Code Highlighter .

, :

[production]

foo = "${bar}"

bar = "${foo}"








, , 7 .



Inf_Config_Placeholder GitHub .



PS GitHub' - , library . , - ?








//

$environment = 'production' ;



//

$rootPath = dirname(__FILE__);



//

$configPath = rootPath . '/application/configs/application.ini' ;



// ""

// read-only

$configRaw = new Zend_Config_Ini($configPath, $environment, true );



//

$configRaw->path->root = $rootPath;



// , "" ""

$config = Inf_Config_Placeholder($configRaw);



// ,



* This source code was highlighted with Source Code Highlighter .






, :

[production]

foo = "${bar}"

bar = "${foo}"








, , 7 .



Inf_Config_Placeholder GitHub .



PS GitHub' - , library . , - ?







All Articles