-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathbootstrap.php
More file actions
89 lines (79 loc) · 2.37 KB
/
bootstrap.php
File metadata and controls
89 lines (79 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace WP_CLI;
use WP_CLI\Bootstrap\BootstrapState;
use WP_CLI\Bootstrap\BootstrapStep;
/**
* Get the list of ordered steps that need to be processed to bootstrap WP-CLI.
*
* Each entry is a fully qualified class name for a class implementing the
* `WP_CLI\Bootstrap\BootstrapStep` interface.
*
* @return string[]
*/
function get_bootstrap_steps() {
return [
Bootstrap\DeclareFallbackFunctions::class,
Bootstrap\LoadUtilityFunctions::class,
Bootstrap\DeclareMainClass::class,
Bootstrap\DeclareAbstractBaseCommand::class,
Bootstrap\IncludeFrameworkAutoloader::class,
Bootstrap\ConfigureRunner::class,
Bootstrap\InitializeColorization::class,
Bootstrap\InitializeLogger::class,
Bootstrap\RegisterShutdownHandler::class,
Bootstrap\CheckRoot::class,
Bootstrap\IncludeRequestsAutoloader::class,
Bootstrap\DefineProtectedCommands::class,
Bootstrap\LoadExecCommand::class,
Bootstrap\LoadRequiredCommand::class,
Bootstrap\IncludePackageAutoloader::class,
Bootstrap\IncludeFallbackAutoloader::class,
Bootstrap\RegisterFrameworkCommands::class,
Bootstrap\RegisterDeferredCommands::class,
Bootstrap\InitializeContexts::class,
Bootstrap\LaunchRunner::class,
];
}
/**
* Register the classes needed for the bootstrap process.
*
* The Composer autoloader is not active yet at this point, so we need to use a
* custom autoloader to fetch the bootstrap classes in a flexible way.
*/
function prepare_bootstrap() {
require_once WP_CLI_ROOT . '/php/WP_CLI/Autoloader.php';
$autoloader = new Autoloader();
$autoloader->add_namespace(
'WP_CLI\Bootstrap',
WP_CLI_ROOT . '/php/WP_CLI/Bootstrap'
)->register();
}
/**
* Initialize and return the bootstrap state to pass from step to step.
*
* @return BootstrapState
*/
function initialize_bootstrap_state() {
return new BootstrapState();
}
/**
* Process the bootstrapping steps.
*
* Loops over each of the provided steps, instantiates it and then calls its
* `process()` method.
*/
function bootstrap() {
prepare_bootstrap();
$state = initialize_bootstrap_state();
foreach ( get_bootstrap_steps() as $step ) {
/** @var BootstrapStep $step_instance */
if ( class_exists( 'WP_CLI' ) ) {
\WP_CLI::debug( "Processing bootstrap step: {$step}", 'bootstrap' );
}
/**
* @var BootstrapStep $step_instance
*/
$step_instance = new $step();
$state = $step_instance->process( $state );
}
}