| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Patches vendor-prefixed/vendor/composer/autoload_static.php after php-scoper runs. |
| 5 |
* |
| 6 |
* autoload_static.php is generated output by php-scoper — patchers in scoper.inc.php |
| 7 |
* don't apply to it. This script adds the BerqWP_Deps\ prefix to all vendor namespace |
| 8 |
* keys so the ClassLoader can resolve BerqWP_Deps\GuzzleHttp\*, BerqWP_Deps\voku\*, etc. |
| 9 |
* |
| 10 |
* Run via: /opt/local/bin/php83 fix-autoload-static.php |
| 11 |
* Called automatically by: make scope |
| 12 |
*/ |
| 13 |
|
| 14 |
$file = __DIR__ . '/vendor-prefixed/vendor/composer/autoload_static.php'; |
| 15 |
|
| 16 |
if (!file_exists($file)) { |
| 17 |
echo "Error: $file not found. Run make scope first.\n"; |
| 18 |
exit(1); |
| 19 |
} |
| 20 |
|
| 21 |
$content = file_get_contents($file); |
| 22 |
|
| 23 |
// These namespaces appear as literal string keys in autoload_static.php. |
| 24 |
// Order matters: longer/more-specific namespaces must come before shorter ones |
| 25 |
// (e.g. GuzzleHttp\Psr7\ before GuzzleHttp\) to avoid double-prefixing. |
| 26 |
$replacements = [ |
| 27 |
"'voku\\\\helper\\\\" => "'BerqWP_Deps\\\\voku\\\\helper\\\\", |
| 28 |
"'Symfony\\\\Polyfill\\\\Php80\\\\" => "'BerqWP_Deps\\\\Symfony\\\\Polyfill\\\\Php80\\\\", |
| 29 |
"'Symfony\\\\Component\\\\CssSelector\\\\" => "'BerqWP_Deps\\\\Symfony\\\\Component\\\\CssSelector\\\\", |
| 30 |
"'Psr\\\\Http\\\\Message\\\\" => "'BerqWP_Deps\\\\Psr\\\\Http\\\\Message\\\\", |
| 31 |
"'Psr\\\\Http\\\\Client\\\\" => "'BerqWP_Deps\\\\Psr\\\\Http\\\\Client\\\\", |
| 32 |
"'GuzzleHttp\\\\Psr7\\\\" => "'BerqWP_Deps\\\\GuzzleHttp\\\\Psr7\\\\", |
| 33 |
"'GuzzleHttp\\\\Promise\\\\" => "'BerqWP_Deps\\\\GuzzleHttp\\\\Promise\\\\", |
| 34 |
"'GuzzleHttp\\\\" => "'BerqWP_Deps\\\\GuzzleHttp\\\\", |
| 35 |
]; |
| 36 |
|
| 37 |
foreach ($replacements as $from => $to) { |
| 38 |
$content = str_replace($from, $to, $content); |
| 39 |
} |
| 40 |
|
| 41 |
// Fix the prefix-length values (ClassLoader uses these to strip the namespace prefix |
| 42 |
// from a class name to get the file path — length must include the BerqWP_Deps\ part). |
| 43 |
$lengths = [ |
| 44 |
'BerqWP_Deps\\\\voku\\\\helper\\\\' => 24, |
| 45 |
'BerqWP_Deps\\\\Symfony\\\\Polyfill\\\\Php80\\\\' => 36, |
| 46 |
'BerqWP_Deps\\\\Symfony\\\\Component\\\\CssSelector\\\\' => 43, |
| 47 |
'BerqWP_Deps\\\\Psr\\\\Http\\\\Message\\\\' => 30, |
| 48 |
'BerqWP_Deps\\\\Psr\\\\Http\\\\Client\\\\' => 29, |
| 49 |
'BerqWP_Deps\\\\GuzzleHttp\\\\Psr7\\\\' => 29, |
| 50 |
'BerqWP_Deps\\\\GuzzleHttp\\\\Promise\\\\' => 32, |
| 51 |
'BerqWP_Deps\\\\GuzzleHttp\\\\' => 24, |
| 52 |
]; |
| 53 |
|
| 54 |
foreach ($lengths as $ns => $len) { |
| 55 |
$content = preg_replace("/'$ns' => \d+/", "'$ns' => $len", $content); |
| 56 |
} |
| 57 |
|
| 58 |
file_put_contents($file, $content); |
| 59 |
echo "autoload_static.php patched successfully.\n"; |
| 60 |
|