PHP 8.4.25 Released!

Yaf_Application::bootstrap

(Yaf >=1.0.0)

Yaf_Application::bootstrapCall bootstrap

Description

public function Yaf_Application::bootstrap(): Yaf_Application|false

Run a Bootstrap. All the public methods of the Bootstrap class whose name starts with _init are called in declaration order, each receiving the Yaf_Dispatcher instance as its only argument.

The Bootstrap class must be named Bootstrap and extend Yaf_Bootstrap_Abstract. If it is not already defined, it is loaded from Bootstrap.php in the application directory; the application.bootstrap configuration entry overrides its location.

Parameters

This function has no parameters.

Return Values

Returns the Yaf_Application object itself on success, or false on failure (for instance if the Bootstrap class could not be loaded, or if an uncaught exception was thrown by one of the _init* methods).

Errors/Exceptions

Triggers a YAF_ERR_TYPE_ERROR error if the found class is not a subclass of Yaf_Bootstrap_Abstract, or an E_WARNING if the bootstrap file or the Bootstrap class cannot be found.

Examples

Example #1 A Bootstrap example

<?php
/**
 * This file should be under 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 {
    public function _initConfig(Yaf_Dispatcher $dispatcher) {
        echo "1st called\n";
    }

    public function _initPlugin(Yaf_Dispatcher $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__);

$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

add a note

User Contributed Notes 1 note

up
1
brandon at brandonlamb dot com
14 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