When drupal_bootstrap is calledfrom index.php it is passed a single argument: BOOTSTRAP_FULL. Inorder for index.php (a php script) to display a web page (what thescript does) it needs Drupal to bootstrap all of its mechanisms(i.e. a full bootstrap).
Lets see what the phpDoc comment and function signature fordrupal_bootstrap() have to say:
<?php
function drupal_bootstrap($phase= NULL,$new_phase = TRUE) {?>
This basically tells us that when we call this function we haveto tell it which bootstrap phase to run by passing a value to the$phase variable. The functionaccepts a second argument $new_phase which by default is "TRUE".
Executing drupal_bootstrap(BOOTSTRAP_FULL)
So the first thing that the function does when its run is definea staticvariable called $phases. Thatvariable is assigned an array that is populated with the constantsthat represent the 7 phases of the bootstrap process.
<?php
<wbr></wbr> static $phases =array(
<wbr><wbr><wbr></wbr></wbr></wbr>DRUPAL_BOOTSTRAP_CONFIGURATION,
<wbr><wbr><wbr></wbr></wbr></wbr>DRUPAL_BOOTSTRAP_PAGE_CACHE,
<wbr><wbr><wbr></wbr></wbr></wbr>DRUPAL_BOOTSTRAP_DATABASE,
<wbr><wbr><wbr></wbr></wbr></wbr>DRUPAL_BOOTSTRAP_VARIABLES,
<wbr><wbr><wbr></wbr></wbr></wbr>DRUPAL_BOOTSTRAP_SESSION,
<wbr><wbr><wbr></wbr></wbr></wbr>DRUPAL_BOOTSTRAP_PAGE_HEADER,
<wbr><wbr><wbr></wbr></wbr></wbr>DRUPAL_BOOTSTRAP_LANGUAGE,
<wbr><wbr><wbr></wbr></wbr></wbr>DRUPAL_BOOTSTRAP_FULL,
<wbr> );<br></wbr>?>
The function then defines two more static variables $final_phase and $stored_phase (given an initial value of-1).
<?php
<wbr></wbr> // When notrecursing, store the phase name so it's not forgotten while
<wbr> // recursing.<br><wbr></wbr></wbr> if($new_phase) {
<wbr><wbr><wbr></wbr></wbr></wbr>$final_phase = $phase;
<wbr> }<br></wbr>?>
$new_phase is TRUE by default -therefore the $final_phase isassigned the value of $phase which in this case is BOOTSTAP_FULL which has an integer value of7.
<?php
<wbr></wbr> if(isset($phase)){
<wbr><wbr><wbr></wbr></wbr></wbr>// Call a phase if it has not beencalled before and is below the requested
<wbr><wbr><wbr> //phase.<br><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>while ($phases &&$phase > $stored_phase &&$final_phase > $stored_phase){
?>
If $phase has a value (it does)the function enters a whileloop. The conditions of the while loop are:
if the $phases array has somethingin it (it currently does)
AND $phase (currently BOOTSTRAP_FULL or 7)
is greater than $stored_phase(currently -1)
AND $final_phase (also currently7)
is greater than $stored_phase(currently -1)
do stuff.
In more general terms, the function is going to keep loopinguntil each bootstrap phase is complete and it reaches the bootstrapphase that was first passed to the function.
<?php
<wbr><wbr><wbr><wbr><wbr>$current_phase</wbr></wbr></wbr></wbr></wbr> =array_shift($phases);
<wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr>// current call actually resulted in a progress in the bootstrapprocess.<br><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> if ( $current_phase > $stored_phase ){
<wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> $stored_phase = $current_phase ;
<wbr><wbr><wbr><wbr><wbr>}<br></wbr></wbr></wbr></wbr></wbr> ?>
Once inside the while loop the function 'shiftsoff' the first value of the $phases array and assigns the value to$current_phase.
If you look back, you'll see that the first element of the$phases array was DRUPAL_BOOTSTRAP_CONFIGURATION. Therefore$current_phase gets assigned thatvalue once the array is shifted.
After that, the function then checks if $current_phase is greater than the $stored_phase and if so assigns the value of$current_phase to $stored_phase. This is all about keeping trackof what the current bootstrap phase is and what the phase was.Remember, this function is going to be looping through all thephases. In each loop drupal_bootstrap could be calledagain recursively.
Meat and Potatoes
We arrive at the part that actually starts doing thebootstrapping (starting up) of the individual parts of Drupal.
<?php
switch ($current_phase) {
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>case</wbr></wbr></wbr></wbr></wbr></wbr></wbr> DRUPAL_BOOTSTRAP_CONFIGURATION:
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>_drupal_bootstrap_configuration();
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>break;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>case</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> _drupal_bootstrap_page_cache ();
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>break;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>case</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
DRUPAL_BOOTSTRAP_DATABASE :<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> _drupal_bootstrap_database ();
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>break;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>case</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
DRUPAL_BOOTSTRAP_VARIABLES :<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> _drupal_bootstrap_variables ();
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>break;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>case</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
DRUPAL_BOOTSTRAP_SESSION :<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>require_once</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> DRUPAL_ROOT . '/' . variable_get ( 'session_inc' , 'includes/session.inc' );
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> drupal_session_initialize ();
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>break;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>case</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
DRUPAL_BOOTSTRAP_PAGE_HEADER :<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> _drupal_bootstrap_page_header ();
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>break;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>case</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
DRUPAL_BOOTSTRAP_LANGUAGE :<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> drupal_language_initialize ();
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>break;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>case</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
DRUPAL_BOOTSTRAP_FULL :<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>require_once</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> DRUPAL_ROOT . '/includes/common.inc' ;
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> _drupal_bootstrap_full ();
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>break;<br><wbr><wbr><wbr><wbr><wbr>}<br></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> ?>
There is a switch/case statement that checks what the$current_phase is and then executesthe code in the appropriate case.
At this stage in this line by line journey the $current_phase is DRUPAL_BOOTSTRAP_CONFIGURATION so
_drupal_bootstrap_configuration()gets called.
What happens next
Good question, but the answer will have to wait. This is a goodtime to stop for now since each phase in the bootstrap processrequires its own post. Next time we'll take a look at _drupal_bootstrap_configuration.
While you are waiting, and if you are at all curious about theorigins of the bootstrap process, you can check out http://drupal.org/node/18213where drupal_bootstrap was born.
本文深入探讨Drupal核心函数drupal_bootstrap()的工作原理,该函数负责逐步加载Drupal的所有必要组件以响应网页请求。文章按阶段详细解释了从配置到完全初始化的过程,并介绍了每个阶段涉及的主要任务。
113

被折叠的 条评论
为什么被折叠?



