Question

I have the following code in my zend application bootstrap file

protected function _initSessionId() {
    $this->bootstrap( 'session' );
    $opts = $this->getOptions();
    $cache = $this->bootstrap( 'cachemanager' )
    ->getResource( 'cachemanager' )
    ->getCache( 'memcached' );
    Zend_Db_Table_Abstract::setDefaultMetadataCache( $cache );

    Zend_Registry::set( 'cache', $cache );
    $defaultNamespace = new Zend_Session_Namespace();
    if ( !isset( $defaultNamespace->initialized ) ) {
        Zend_Session::regenerateId();
        $defaultNamespace->initialized = true;
    }
}

I want to know what the line $this->bootstrap('session') actually does. Which class/function does it instantiate and call?

Was it helpful?

Solution

How to bootstrap a resource

bootstrap(<resource_name>) tells to Zend_Bootstrap to init the specified resource before continue. Usually is used for init required dependencies before init the actual resource

The resource bootstrap can be declared in two ways.

A PHP method in the Bootstrap class.

function _init<Resource_name>() { ... }

Or in the ini file

resources.<resource_name>

in the last case (ini file) a class extending from Zend_Application_Resource_ResourceAbstract must be declared with the code for init the resource.

Session resource bootstrap

For the concrete case of bootstrap('session') by default use the init() method declared in Zend_Application_Resource_Session

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top