Skip to content

Commit 46bc3ec

Browse files
authored
Merge pull request #85 from wp-cli/fix-maintenance-autoload
Run the maintenance code of the checkout you are in
2 parents 0b66e8e + 2aa8f6d commit 46bc3ec

1 file changed

Lines changed: 12 additions & 24 deletions

File tree

‎.maintenance/autoload.php‎

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
11
<?php
22
/**
3-
* Loads the maintenance commands.
3+
* Loads the maintenance commands of this checkout.
44
*
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
76
* 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.
813
*/
914

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;
3018
}
31-
);
19+
}
3220

3321
require_once __DIR__ . '/bootstrap.php';

0 commit comments

Comments
 (0)