fetus Diary

2008/08/20(水) - Zend Framework で module 名と controllers パスの関係を ini ファイルから読み込んでみるテスト

[modules]
enabled = "hoge,fuga,piyo"
module.hoge.controllers = "/path/to/controllers"
module.fuga.controllers = "<AUTO>"
; module.piyo.controllers は <AUTO> に自動設定(default)
$controller = Zend_Controller_Front::getInstance();
if(file_exists(MOND_CONFIG . '/modules.ini')) {
    $config_modules = new Zend_Config_Ini(MOND_CONFIG . '/modules.ini', 'modules');
    if(isset($config_modules->enabled)) {
        $controllers = array();
        foreach(explode(',', $config_modules->enabled) as $module) {
            $module = trim($module);
            $controllers_path = '<AUTO>';
            if(isset($config_modules->module) &&
               isset($config_modules->module->$module) &&
               isset($config_modules->module->$module->controllers))
            {
                $controllers_path = $config_modules->module->$module->controllers;
            }
            $controllers_path = str_replace('<AUTO>',
                                            sprintf('%s/%s/%s',
                                                    MOND_MODULES, // <MODULES>
                                                    $module,
                                                    'controllers'),
                                            $controllers_path);
            $controllers_path = str_replace('<MODULES>',
                                            MOND_MODULES,
                                            $controllers_path);
            $controllers[$module] = $controllers_path;
        }
        $controller->setControllerDirectory($controllers);
    }
}

果てしなく無駄な事をやっている気がしてならない。っていうか毎回 bootstrup として走らせるには重い気がする。

気にするだけ無駄って話もあるけど。重いなら Mojavi 風に compile してみるとか(ぉ

# webapplication の path に UTF-8 でマルチバイトになるような文字は使わないので str_replace でも悲しい目には遭わないと想定

関係あるかも?

このエントリは次のエントリから参照されているみたいです

コメント

コメントはありません。

名前
メール
コメント

※HTML タグは使えません。HTTP URL には自動リンクが張られます。

Captcha
画像から読み取れる文字を入力: