Mais conteúdo relacionado
Semelhante a CakePHP2 Loading (Japanese) (20)
CakePHP2 Loading (Japanese)
- 4. LOADING
• ファイル探索
• ファイルインポート(include, require)
• インスタンス生成
- 5. アジェンダ
• App::build()
• App::import()
• AutoLoading
• LazyLoading
- 6. App::build()
• app/bootstrap.phpに定義
• 標準以外の読み込みPATHを定義
– ex. 複数のプラグインフォルダを使いたい
- 7. App::build()
1.3
App::build(array(
'controllers' => array(
'/home/user/app1/Controller',
'/home/user/app2/Controller',
)
))
2.0
App::build(array(
'Controller' => array(
'/home/user/app1/Controller',
'/home/user/app2/Controller',
)
))
- 8. アジェンダ
• App::build()
• App::import()
• AutoLoading
• LazyLoading
- 9. App::import()
• ファイルの読み込み(include/require)
– 例 App::import('Controller', 'UserGroup');
• ファイル探索
– 1.3 : ディレクトリ再帰探索
– 2.0 : 再帰探索しない
• ファイルのインポート処理
– 1.3:すぐにinclude, require
– 2.0:クラス利用時にinclude, require
- 10. アジェンダ
• App::build()
• App::import()
• AutoLoading
• LazyLoading
- 11. Autoload
• __autoload()
– 未定義のクラス/インターフェイスを使用し
ようとした時に 自動的にコールされる
– new Hoge()するまでrequireしない
• インポート負荷の軽減
function __autoload($class_name) {
include $class_name . '.php';
}
$obj = new MyClass1();
$obj2 = new MyClass2();
- 12. Autoload
• App::uses('EmailComponent', 'Controller/Component')
– クラス名と格納場所を登録するのみ
• new EmailComponent()した時にautoloadの仕組みを
使ってincludeされる
– App::load()がspl_autoload_register()から呼び出され
る
– cake/Cake/bootstrap.php
• spl_autoload_register(array('App', 'load'));
- 14. アジェンダ
• App::build()
• App::import()
• AutoLoading
• LazyLoading
- 15. LazyLoading
• AutoLoadingはinclude/requireのタイミング
• LazyLoadingはインスタンス生成のタイミング
- 16. LazyLoading
• CakePHP1.3
– アクションで利用しないモデルオブジェクトまで生成
class PostsController extends AppController {
public $uses = array('Post','Event');
function index() {
$this->Post->recursive = 0;
$this->set('posts', $this-
>paginate());
}
- 17. LazyLoading
• CakePHP1.3
– cake/dispatcher.php
– controller::constructClasses()
– controller::loadModel()
– ClassRegistry::init()
• new Model()
- 18. LazyLoading
• CakePHP2.0
– Controller::usesで定義してもモデルオブジェク
トは生成されない
– コントローラのプロパティ変数($this->Model)
にアクセスした時に初めてオブジェクト生成
• 不要なオブジェクト生成を回避
• マジックメソッドを利用
- 19. LazyLoading
• CakePHP2.0
– $this->Post->find(); //controller
– Controller::__get() でisset()
– Controller::__isset()
– Controller::loadModel()
– ClassRegistry::init()
• new Model()
- 20. Conclusion
• CakePHP2.0
– Autoload, LazyLoadの機能によりパフォーマ
ンスアップ
– App::import()のPath再帰探索がなくなったの
で注意
- 21. ロード 第2章へ・・・
Thank you
http://www.facebook.com/CakeRadioGaGa