PHP Conference Nagoya 2025

Yaf_Application::bootstrap

(Yaf >=1.0.0)

Yaf_Application::bootstrapCall bootstrap

Açıklama

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

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.

Bağımsız Değişkenler

bootstrap

A Yaf_Bootstrap_Abstract instance

Dönen Değerler

Yaf_Application instance

Örnekler

Örnek 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";
}
}
?>

Örnek 2 Yaf_Application::bootstrap()example

<?php

defined
('APPLICATION_PATH') // APPLICATION_PATH will be used in the ini config file
|| define('APPLICATION_PATH', __DIR__);

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

Yukarıdaki örnek şuna benzer bir çıktı üretir:

1st called
2nd called

Ayrıca Bakınız

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