CoreBootstrap

Filepath: phork/php/core/CoreBootstrap.class.php and phork/php/app/AppBootstrap.class.php

The CoreBootstrap does most of the heavy lifting before delegating the page-specific functionality to a controller. The boostrapping chapter has a more in-depth overview of what a bootstrap does.

This class is broken up into several small methods which should make it easier to extend. The most commonly overriden methods include:

protected function setPaths();
protected function loadConfig();
protected function loadLanguage();
protected function loadLibs();
protected function initDebugging();
protected function startSession();
public function fatal($intErrorCode = null);
public function determineController();

The default controller is defined in CoreBootstrap as CoreControllerLite however this can be changed across all sites in AppBootstrap, or changed on a per-site basis by extending the bootstrap, for example phork/sites/[sitetype]/bootstraps/SiteBootstrap.class.php. The default controller is generally only called for the site's index page if it hasn't been explicitly routed to a new controller. The rest of the pages usually have their own controller. See the routing chapter for more information on how the controller is determined.

It's possible to use the public changeController() method to forward processing to a different controller. This is usually called from a hook or another controller. The CoreUrl chapter details a similar method of forwarding that also changes the application's CoreUrl properties.


Controller Forwarding Example

$objBootstrap = AppRegistry::get('Bootstrap');
$objBootstrap->changeController('MyNewController');

Default Controller Extension Example

require_once('php/core/CoreBootstrap.class.php');

class SiteBootstrap extends CoreBootstrap {
    protected $strDefaultController = 'SiteController';
}

Bootstrap with Beta Site Example

require_once('php/core/CoreBootstrap.class.php');

class SiteBootstrap extends CoreBootstrap {
    protected $strDefaultController = 'SiteController';
    
    /**
     * Determines which controller to use based on the
     * parsed URL. Has special handling to allow a forced
     * beta site for unlogged in users.
     *
     * @access public
     * @return string The controller to use
     */
    public function determineController() {
        if (AppConfig::get('PrivateBeta', false) && !in_array(AppRegistry::get('Url')->getSegment(0), array('api', 'concat'))) {
            if ($objUserLogin = AppRegistry::get('UserLogin', false)) {
                if ($blnLoggedIn = $objUserLogin->isLoggedIn()) {
                    return parent::determineController();
                }
            }
            return 'BetaController';
        }
        return parent::determineController();
    }
}