Yaf_Application::bootstrap

(Yaf >=1.0.0)

Yaf_Application::bootstrapブートストラップをコールする

説明

public Yaf_Application::bootstrap(Yaf_Bootstrap_Abstract $bootstrap = ?): void

ブートストラップを実行します。"_init" で始まる名前のすべてのメソッドを その定義順に実行します。bootstrap パラメータを省略した場合は、 application.directory からブートストラップを探します。

パラメータ

bootstrap

Yaf_Bootstrap_Abstract のインスタンス。

返り値

Yaf_Application のインスタンスを返します。

例1 Bootstrap() の例

<?php
/**
 * ファイルは APPLICATION_PATH . "/application/"
 * (Yaf_Application に渡した設定で定義した場所) に置き、
 * Bootstrap.php という名前にして Yaf_Application から見つけられるようにします
 */
class Bootstrap extends Yaf_Bootstrap_Abstract {
    function 
_initConfig(Yaf_Dispatcher $dispatcher) {
        echo 
"1st called\n";
    }

    function 
_initPlugin($dispatcher) {
        echo 
"2nd called\n";
    }
}
?>

例2 Yaf_Application::bootstrap() の例

<?php

defined
('APPLICATION_PATH')                  // APPLICATION_PATH が ini ファイルで設定されていれば使います
    
|| define('APPLICATION_PATH'__DIR__));

$application = new Yaf_Application(APPLICATION_PATH.'/conf/application.ini');
$application->bootstrap();
?>

上の例の出力は、 たとえば以下のようになります。

1st called
2nd called
add a note add a note

User Contributed Notes 1 note

up
3
brandon at brandonlamb dot com
12 years ago
Here is an example of a Bootstrap loading a session class then loading a database class and using a db configuration from the application config.

<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
    public function
_initSession(Yaf_Dispatcher $dispatcher)
    {
       
$session = new Vendor\Session();
       
$session->start();
    }

    public function
_initDatabase(Yaf_Dispatcher $dispatcher)
    {
       
$config = Yaf_Application::app()->getConfig()->application->database;
       
Yaf_Registry::set('db', Vendor\Database($config));
    }
}
?>
To Top