Yaf_Application::bootstrap

(Yaf >=1.0.0)

Yaf_Application::bootstrapAppelle bootstrap

Description

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

Exécute un Bootstrap, toutes les méthodes définies dans le Bootstrap et nommées avec un préfixe "_init" seront appelées dans l'ordre de leurs déclarations si le paramètre bootstrap n'est pas fourni, Yaf recherchera un Bootstrap dans le dossier de l'application.

Liste de paramètres

bootstrap

Une instance Yaf_Bootstrap_Abstract.

Valeurs de retour

Une instance de la classe Yaf_Application.

Exemples

Exemple #1 Exemple avec A Bootstrap()

<?php
/**
 * Ce fichier doit être dans le APPLICATION_PATH . "/application/"(qui a été défini dans la configuration passée à Yaf_Application).
 * et être nommé Bootstrap.php, aussi, Yaf_Application peut le trouver
 */
class Bootstrap extends Yaf_Bootstrap_Abstract {
    function 
_initConfig(Yaf_Dispatcher $dispatcher) {
        echo 
"1er appel\n";
    }

    function 
_initPlugin($dispatcher) {
        echo 
"2ème appel\n";
    }
}
?>

Exemple #2 Exemple avec Yaf_Application::bootstrap()

<?php

defined
('APPLICATION_PATH')                  // APPLICATION_PATH sera utilisé dans le fichier de configuration ini
    
|| define('APPLICATION_PATH'__DIR__));

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

Résultat de l'exemple ci-dessus est similaire à :

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