Skip to content

Commit 24cccaa

Browse files
schlesseraclaude
andcommitted
Load the maintenance classes of the checkout that runs them
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1f53300 commit 24cccaa

1 file changed

Lines changed: 10 additions & 24 deletions

File tree

‎.maintenance/autoload.php‎

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
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+
foreach ( glob( __DIR__ . '/src/*.php' ) as $maintenance_class_file ) {
16+
require_once $maintenance_class_file;
1517
}
1618

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-
}
30-
}
31-
);
32-
3319
require_once __DIR__ . '/bootstrap.php';

0 commit comments

Comments
 (0)