|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Loads the maintenance commands. |
| 3 | + * Loads the maintenance commands of this checkout. |
4 | 4 | * |
5 | | - * Within a full development environment, Composer does that. Without one, any |
6 | | - * `wp` executable can still run them, so the maintenance tooling only needs |
| 5 | + * Any `wp` executable can run them, so the maintenance tooling only needs |
7 | 6 | * WP-CLI, git and the GitHub CLI, not a complete install of every package. |
| 7 | + * |
| 8 | + * The classes are loaded right away instead of through an autoloader. The |
| 9 | + * `wp` executable may belong to another checkout, such as the main checkout |
| 10 | + * run within a worktree, and its Composer autoloader maps the same namespace. |
| 11 | + * WP-CLI registers that autoloader after this file runs, so it would take |
| 12 | + * precedence and silently run the other checkout's, possibly older, code. |
8 | 13 | */ |
9 | 14 |
|
10 | | -$composer_autoloader = dirname( __DIR__ ) . '/vendor/autoload.php'; |
11 | | - |
12 | | -if ( is_file( $composer_autoloader ) ) { |
13 | | - require_once $composer_autoloader; |
14 | | - return; |
15 | | -} |
16 | | - |
17 | | -spl_autoload_register( |
18 | | - static function ( $class_name ) { |
19 | | - $prefix = 'WP_CLI\\Maintenance\\'; |
20 | | - |
21 | | - if ( 0 !== strpos( $class_name, $prefix ) ) { |
22 | | - return; |
23 | | - } |
24 | | - |
25 | | - $file = __DIR__ . '/src/' . str_replace( '\\', '/', substr( $class_name, strlen( $prefix ) ) ) . '.php'; |
26 | | - |
27 | | - if ( is_file( $file ) ) { |
28 | | - require $file; |
29 | | - } |
| 15 | +foreach ( (array) scandir( __DIR__ . '/src' ) as $maintenance_class_file ) { |
| 16 | + if ( '.php' === substr( (string) $maintenance_class_file, -4 ) ) { |
| 17 | + require_once __DIR__ . '/src/' . $maintenance_class_file; |
30 | 18 | } |
31 | | -); |
| 19 | +} |
32 | 20 |
|
33 | 21 | require_once __DIR__ . '/bootstrap.php'; |
0 commit comments