PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 4.0.21
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v4.0.21
4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 1.9.4 1.9.5 1.9.6 All 170 releases
searchpro / BerqWP / fix-autoload-static.php

fix-autoload-static.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 4.0.21, at BerqWP/fix-autoload-static.php

60 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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