Yaf_Application::bootstrap
(Yaf >=1.0.0)
Yaf_Application::bootstrap — Call bootstrap
Description
Run a Bootstrap, all the methods defined in the Bootstrap and named with prefix "_init" will be called according to their declaration order, if the parameter bootstrap is not supplied, Yaf will look for a Bootstrap under application.directory.
Parameters
-
bootstrap
-
A Yaf_Bootstrap_Abstract instance
Return Values
Yaf_Application instance
Examples
Example #1 A Bootstrap()example
<?php
/**
* This file should be under the APPLICATION_PATH . "/application/"(which was defined in the config passed to Yaf_Application).
* and named Bootstrap.php, so the Yaf_Application can find it
*/
class Bootstrap extends Yaf_Bootstrap_Abstract {
function _initConfig(Yaf_Dispatcher $dispatcher) {
echo "1st called\n";
}
function _initPlugin($dispatcher) {
echo "2nd called\n";
}
}
?>
Example #2 Yaf_Application::bootstrap()example
<?php
defined('APPLICATION_PATH') // APPLICATION_PATH will be used in the ini config file
|| define('APPLICATION_PATH', __DIR__)); //__DIR__ was introduced after PHP 5.3
$application = new Yaf_Application(APPLICATION_PATH.'/conf/application.ini');
$application->bootstrap();
?>
The above example will output something similar to:
1st called 2nd called
See Also
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Другие базовые расширения
- Yet Another Framework
- Функция Yaf_Application::app() - Retrieve an Application instance
- Функция Yaf_Application::bootstrap() - Call bootstrap
- Функция Yaf_Application::clearLastError() - Clear the last error info
- Функция Yaf_Application::__clone() - Yaf_Application can not be cloned
- Функция Yaf_Application::__construct() - Yaf_Application constructor
- Функция Yaf_Application::__destruct() - The __destruct purpose
- Функция Yaf_Application::environ() - Retrive environ
- Функция Yaf_Application::execute() - Execute a callback
- Функция Yaf_Application::getAppDirectory() - Get the application directory
- Функция Yaf_Application::getConfig() - Retrive the config instance
- Функция Yaf_Application::getDispatcher() - Get Yaf_Dispatcher instance
- Функция Yaf_Application::getLastErrorMsg() - Get message of the last occurred error
- Функция Yaf_Application::getLastErrorNo() - Get code of last occurred error
- Функция Yaf_Application::getModules() - Get defined module names
- Функция Yaf_Application::run() - Start Yaf_Application
- Функция Yaf_Application::setAppDirectory() - Change the application directory
- Функция Yaf_Application::__sleep() - Yaf_Application can not be serialized
- Функция Yaf_Application::__wakeup() - Yaf_Application can not be unserialized
Коментарии
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));
}
}
?>