@@ -142,15 +142,7 @@ function drush_bootstrap_value($context, $value = null) {
142142 * @see \Drush\Boot\Boot::bootstrapPhases()
143143 */
144144function _drush_bootstrap_phases ($ function_names = FALSE ) {
145- $ result = array ();
146-
147- if ($ bootstrap = Drush::bootstrap ()) {
148- $ result = $ bootstrap ->bootstrapPhases ();
149- if (!$ function_names ) {
150- $ result = array_keys ($ result );
151- }
152- }
153- return $ result ;
145+ return Drush::bootstrapManager ()->bootstrapPhases ($ phase , $ phase_max );
154146}
155147
156148/**
@@ -173,51 +165,7 @@ function _drush_bootstrap_phases($function_names = FALSE) {
173165 * @see \Drush\Boot\Boot::bootstrapPhases()
174166 */
175167function drush_bootstrap ($ phase , $ phase_max = FALSE ) {
176- $ bootstrap = Drush::bootstrap ();
177- $ phases = _drush_bootstrap_phases (TRUE );
178- $ result = TRUE ;
179-
180- // If the requested phase does not exist in the list of available
181- // phases, it means that the command requires bootstrap to a certain
182- // level, but no site root could be found.
183- if (!isset ($ phases [$ phase ])) {
184- $ result = drush_bootstrap_error ('DRUSH_NO_SITE ' , dt ("We could not find an applicable site for that command. " ));
185- }
186-
187- // Once we start bootstrapping past the DRUSH_BOOTSTRAP_DRUSH phase, we
188- // will latch the bootstrap object, and prevent it from changing.
189- if ($ phase > DRUSH_BOOTSTRAP_DRUSH ) {
190- Drush::bootstrapManager ()->latch ($ bootstrap );
191- }
192-
193- drush_set_context ('DRUSH_BOOTSTRAPPING ' , TRUE );
194- foreach ($ phases as $ phase_index => $ current_phase ) {
195- $ bootstrapped_phase = drush_get_context ('DRUSH_BOOTSTRAP_PHASE ' , -1 );
196- if ($ phase_index > $ phase ) {
197- break ;
198- }
199- if ($ phase_index > $ bootstrapped_phase ) {
200- if ($ result = drush_bootstrap_validate ($ phase_index )) {
201- if (method_exists ($ bootstrap , $ current_phase ) && !drush_get_error ()) {
202- drush_log (dt ("Drush bootstrap phase : !function() " , array ('!function ' => $ current_phase )), LogLevel::BOOTSTRAP );
203- $ bootstrap ->{$ current_phase }();
204-
205- // Reset commandfile cache and find any new command files that are available during this bootstrap phase.
206- drush_get_commands (TRUE );
207- _drush_find_commandfiles ($ phase_index , $ phase_max );
208- }
209- drush_set_context ('DRUSH_BOOTSTRAP_PHASE ' , $ phase_index );
210- }
211- }
212- }
213- drush_set_context ('DRUSH_BOOTSTRAPPING ' , FALSE );
214- if (!$ result || drush_get_error ()) {
215- $ errors = drush_get_context ('DRUSH_BOOTSTRAP_ERRORS ' , array ());
216- foreach ($ errors as $ code => $ message ) {
217- drush_set_error ($ code , $ message );
218- }
219- }
220- return !drush_get_error ();
168+ return Drush::bootstrapManager ()->doBootstrap ($ phase , $ phase_max );
221169}
222170
223171/**
@@ -235,9 +183,7 @@ function drush_bootstrap($phase, $phase_max = FALSE) {
235183 * TRUE if the specified bootstrap phase has completed.
236184 */
237185function drush_has_boostrapped ($ phase ) {
238- $ phase_index = drush_get_context ('DRUSH_BOOTSTRAP_PHASE ' );
239-
240- return isset ($ phase_index ) && ($ phase_index >= $ phase );
186+ return Drush::bootstrapManager ()->hasBootstrapped ($ phase );
241187}
242188
243189/**
@@ -260,32 +206,7 @@ function drush_has_boostrapped($phase) {
260206 * @see \Drush\Boot\Boot::bootstrapPhases()
261207 */
262208function drush_bootstrap_validate ($ phase ) {
263- $ bootstrap = Drush::bootstrap ();
264- $ phases = _drush_bootstrap_phases (TRUE );
265- static $ result_cache = array ();
266-
267- if (!array_key_exists ($ phase , $ result_cache )) {
268- drush_set_context ('DRUSH_BOOTSTRAP_ERRORS ' , array ());
269- drush_set_context ('DRUSH_BOOTSTRAP_VALUES ' , array ());
270-
271- foreach ($ phases as $ phase_index => $ current_phase ) {
272- $ validated_phase = drush_get_context ('DRUSH_BOOTSTRAP_VALIDATION_PHASE ' , -1 );
273- if ($ phase_index > $ phase ) {
274- break ;
275- }
276- if ($ phase_index > $ validated_phase ) {
277- $ current_phase .= 'Validate ' ;
278- if (method_exists ($ bootstrap , $ current_phase )) {
279- $ result_cache [$ phase_index ] = $ bootstrap ->{$ current_phase }();
280- }
281- else {
282- $ result_cache [$ phase_index ] = TRUE ;
283- }
284- drush_set_context ('DRUSH_BOOTSTRAP_VALIDATION_PHASE ' , $ phase_index );
285- }
286- }
287- }
288- return $ result_cache [$ phase ];
209+ return Drush::bootstrapManager ()->bootstrapValidate ($ phase );
289210}
290211
291212/**
@@ -298,37 +219,7 @@ function drush_bootstrap_validate($phase) {
298219 * TRUE if the specified bootstrap phase has completed.
299220 */
300221function drush_bootstrap_to_phase ($ max_phase_index ) {
301- if ($ max_phase_index == DRUSH_BOOTSTRAP_MAX ) {
302- // Bootstrap as far as we can without throwing an error, but log for
303- // debugging purposes.
304- drush_log (dt ("Trying to bootstrap as far as we can. " ), 'debug ' );
305- drush_bootstrap_max ();
306- return TRUE ;
307- }
308-
309- drush_log (dt ("Bootstrap to phase !phase. " , array ('!phase ' => $ max_phase_index )), LogLevel::BOOTSTRAP );
310- $ phases = _drush_bootstrap_phases ();
311- $ result = TRUE ;
312-
313- // Try to bootstrap to the maximum possible level, without generating errors
314- foreach ($ phases as $ phase_index ) {
315- if ($ phase_index > $ max_phase_index ) {
316- // Stop trying, since we achieved what was specified.
317- break ;
318- }
319-
320- if (drush_bootstrap_validate ($ phase_index )) {
321- if ($ phase_index > drush_get_context ('DRUSH_BOOTSTRAP_PHASE ' , DRUSH_BOOTSTRAP_NONE )) {
322- $ result = drush_bootstrap ($ phase_index , $ max_phase_index );
323- }
324- }
325- else {
326- $ result = FALSE ;
327- break ;
328- }
329- }
330-
331- return $ result ;
222+ return Drush::bootstrapManager ()->bootstrapToPhase ($ max_phase_index );
332223}
333224
334225/**
@@ -341,33 +232,7 @@ function drush_bootstrap_to_phase($max_phase_index) {
341232 * The maximum phase to which we bootstrapped.
342233 */
343234function drush_bootstrap_max ($ max_phase_index = FALSE ) {
344- $ phases = _drush_bootstrap_phases (TRUE );
345- if (!$ max_phase_index ) {
346- $ max_phase_index = count ($ phases );
347- }
348-
349- // Try to bootstrap to the maximum possible level, without generating errors.
350- foreach ($ phases as $ phase_index => $ current_phase ) {
351- if ($ phase_index > $ max_phase_index ) {
352- // Stop trying, since we achieved what was specified.
353- break ;
354- }
355-
356- if (drush_bootstrap_validate ($ phase_index )) {
357- if ($ phase_index > drush_get_context ('DRUSH_BOOTSTRAP_PHASE ' )) {
358- drush_bootstrap ($ phase_index , $ max_phase_index );
359- }
360- }
361- else {
362- // drush_bootstrap_validate() only logs successful validations. For us,
363- // knowing what failed can also be important.
364- $ previous = drush_get_context ('DRUSH_BOOTSTRAP_PHASE ' );
365- drush_log (dt ("Bootstrap phase !function() failed to validate; continuing at !current(). " , array ('!function ' => $ current_phase , '!current ' => $ phases [$ previous ])), 'debug ' );
366- break ;
367- }
368- }
369-
370- return drush_get_context ('DRUSH_BOOTSTRAP_PHASE ' );
235+ return Drush::bootstrapManager ()->bootstrapMax ($ max_phase_index );
371236}
372237
373238/**
0 commit comments