PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 4.0.19
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v4.0.19
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 / scoper.inc.php

scoper.inc.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 4.0.19, at BerqWP/scoper.inc.php

89 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 use Isolated\Symfony\Component\Finder\Finder;
6
7 return [
8 'prefix' => 'BerqWP_Deps',
9
10 'finders' => [
11 // Third-party vendor packages
12 Finder::create()
13 ->files()
14 ->in(__DIR__ . '/vendor')
15 ->name('*.php'),
16
17 // SDK source — so GuzzleHttp/voku use statements get rewritten automatically
18 Finder::create()
19 ->files()
20 ->in(__DIR__ . '/src')
21 ->name('*.php'),
22 ],
23
24 'exclude-namespaces' => [
25 'BerqWP', // plugin's own namespace — never prefix
26 'Composer', // composer internals
27 ],
28
29 'exclude-classes' => [
30 // polyfill-php80 global stubs
31 'Attribute',
32 'PhpToken',
33 'Stringable',
34 'UnhandledMatchError',
35 'ValueError',
36 ],
37
38 'exclude-functions' => [
39 'getallheaders', // ralouphie/getallheaders
40 'fdiv',
41 'preg_last_error_msg',
42 'str_contains',
43 'str_starts_with',
44 'str_ends_with',
45 'get_debug_type',
46 'get_resource_id', // symfony/polyfill-php80
47 'trigger_deprecation', // symfony/deprecation-contracts
48 ],
49
50 'exclude-constants' => [
51 'ABSPATH',
52 'WP_CONTENT_DIR',
53 ],
54
55 'patchers' => [
56 // autoload_static.php lives in namespace Composer\Autoload, so its PSR-4 map
57 // keys are literal strings without the BerqWP_Deps prefix. PHP-Scoper doesn't
58 // rewrite them because it excludes the Composer namespace. This patcher adds
59 // the prefix to every vendor namespace key so the ClassLoader can resolve
60 // BerqWP_Deps\GuzzleHttp\*, BerqWP_Deps\voku\*, etc.
61 static function (string $filePath, string $prefix, string $content): string {
62 if (!str_ends_with($filePath, 'composer/autoload_static.php')) {
63 return $content;
64 }
65
66 $vendorNamespaces = [
67 'voku\\helper\\' => 24,
68 'Symfony\\Polyfill\\Php80\\' => 36,
69 'Symfony\\Component\\CssSelector\\' => 43,
70 'Psr\\Http\\Message\\' => 30,
71 'Psr\\Http\\Client\\' => 29,
72 'GuzzleHttp\\Psr7\\' => 29,
73 'GuzzleHttp\\Promise\\' => 32,
74 'GuzzleHttp\\' => 24,
75 ];
76
77 foreach ($vendorNamespaces as $ns => $newLen) {
78 // Prefix the key in $prefixLengthsPsr4 and $prefixDirsPsr4
79 $content = str_replace("'$ns'", "'{$prefix}\\\\{$ns}'", $content);
80 // Fix the length value (original length without prefix → new length with prefix)
81 $oldLen = strlen($ns);
82 $content = str_replace("'{$prefix}\\\\{$ns}' => $oldLen", "'{$prefix}\\\\{$ns}' => $newLen", $content);
83 }
84
85 return $content;
86 },
87 ],
88 ];
89