Skip to content

Commit dad0ebe

Browse files
committed
Add support for replacement files.
1 parent 33ee116 commit dad0ebe

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@
6060
"library/README.md",
6161
"LICENSE",
6262
"README.md"
63-
]
63+
],
64+
"replace": {
65+
"library/Requests.php": "Requests.php"
66+
}
6467
},
6568
"simplepie/simplepie": {
6669
"target": "src/wp-includes/SimplePie",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Loads the old Requests class file when the autoloader
4+
* references the original PSR-0 Requests class.
5+
*
6+
* @deprecated 6.2.0
7+
* @package WordPress
8+
* @subpackage Requests
9+
* @since 6.2.0
10+
*/
11+
12+
include_once ABSPATH . WPINC . '/class-requests.php';

tools/composer/src/CustomInstaller.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,37 @@ private function modifyPaths( PackageInterface $package ): void {
110110
$installPath = $this->getInstallPath( $package );
111111

112112
$this->applySourceSubdirectory( $package, $installPath );
113+
$this->applyReplacements( $package, $installPath );
113114
$this->applyIgnorePatterns( $package, $installPath );
114115
}
115116

117+
/**
118+
* Apply file replacements from custom replacement files.
119+
*
120+
* @param PackageInterface $package The package.
121+
* @param string $installPath The installation path.
122+
*/
123+
private function applyReplacements( PackageInterface $package, string $installPath ): void {
124+
$packageName = $package->getName();
125+
126+
if ( ! isset( $this->installerPaths[ $packageName ]['replace'] ) ) {
127+
return;
128+
}
129+
130+
$filesystem = new Filesystem();
131+
$replacementsDir = realpath( getcwd() ) . '/tools/composer/replacements';
132+
133+
foreach ( $this->installerPaths[ $packageName ]['replace'] as $target => $source ) {
134+
$sourcePath = $replacementsDir . '/' . $source;
135+
136+
if ( ! file_exists( $sourcePath ) ) {
137+
throw new \RuntimeException( "Replacement file 'tools/composer/replacements/{$source}' does not exist for package '{$packageName}'." );
138+
}
139+
140+
$filesystem->copy( $sourcePath, $installPath . '/' . $target );
141+
}
142+
}
143+
116144
/**
117145
* Apply ignore patterns to remove unwanted files after installation.
118146
*

0 commit comments

Comments
 (0)