php8.5
Home/ Manual/ yaf / yaf_application/ Yaf_Application::bootstrap

Yaf_Application::bootstrap

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Call bootstrap

Description

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 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

A Bootstrap example

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

Yaf_Application::bootstrap() example

php
<?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:

output
1st called
2nd called

See Also

  • Yaf_Bootstrap_Abstract
  • Yaf_Application::run

Source: reference/yaf/yaf_application/bootstrap.xml · from the official PHP manual (php/doc-en)