DIContainer
function &_createDIContainer()
$config = parse_ini_file(BASE_INI, TRUE); $container =& DIContainerFactory::getContainer(); foreach ($config as $key => $value) { // クラスファイルの読込とインスタンスの生成 }
webapp/config/base.ini
[ConfigUtils] name = ConfigUtils path = core/ConfigUtils.class.php [Request] name = Request path = core/Request.class.php [Response] name = Response path = core/Response.class.php [ActionChain] name = ActionChain path = core/ActionChain.class.php [FilterChain] name = FilterChain path = core/FilterChain.class.php
これはXMLじゃないから単純で分かりやすくていいなぁ。
DIContainerってどういうときに有用なんだっけ。。
ちょっとWEB+DBを読む。
あぁそうか。
普通に new してたら、ある時点で Request クラスを拡張して自動的にフォームの半角カタカナを全角にする FormRequest クラスを作ったとしても、ソースのあちこちにある new Request を書き換えなきゃいけないのか。それを設定ファイル1行変更するだけで済む。
便利だなぁ。
もっと早く勉強しとくべきだったか。。
DIContainer.class.php では他にも function _injectAttributes() に何やら複雑な処理が。
DIContainerFactory.class.php の &create($filename) ってどこから呼び出されるんだろ。。眠い。。