From 587dcb64eb076f1a9b7070c13fb5df8e1d91d8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= <5175937+theofidry@users.noreply.github.com> Date: Sun, 5 Nov 2023 20:02:36 +0100 Subject: [PATCH] build: Simplify the PHP-Scoper configuration (#1146) - Leverage the PHP-Scoper scripts. - Doing the above actually fix some symbols from the Solr extension that were aliased due to a PHPStorm stub directory not being loaded correctly. - Remove the unnecessary polyfill whitelisted (obsolete as of PHP-Scoper 0.18.0). - Exclude some UV related symbols here while waiting for a patch in PHP-Scoper. --- res/scoper-phpstorm-stubs-map-patcher.php | 39 ------------------ res/scoper-phpstorm-stubs.php | 49 ----------------------- res/scoper-polyfills.php | 42 ------------------- scoper.inc.php | 23 ++++++----- 4 files changed, 13 insertions(+), 140 deletions(-) delete mode 100644 res/scoper-phpstorm-stubs-map-patcher.php delete mode 100644 res/scoper-phpstorm-stubs.php delete mode 100644 res/scoper-polyfills.php diff --git a/res/scoper-phpstorm-stubs-map-patcher.php b/res/scoper-phpstorm-stubs-map-patcher.php deleted file mode 100644 index 17914f73f..000000000 --- a/res/scoper-phpstorm-stubs-map-patcher.php +++ /dev/null @@ -1,39 +0,0 @@ - - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -$stubsMapVendorPath = 'vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php'; -$stubsMapPath = __DIR__.'/../'.$stubsMapVendorPath; -$stubsMapOriginalContent = file_get_contents($stubsMapPath); - -if (!preg_match('/class PhpStormStubsMap([\s\S]+)/', $stubsMapOriginalContent, $matches)) { - throw new InvalidArgumentException('Could not capture the map original content.'); -} - -$stubsMapClassOriginalContent = $matches[1]; - -return static function (string $filePath, string $prefix, string $contents) -use ( - $stubsMapVendorPath, - $stubsMapClassOriginalContent, -): string { - if ($filePath !== $stubsMapVendorPath) { - return $contents; - } - - return preg_replace( - '/class PhpStormStubsMap([\s\S]+)/', - 'class PhpStormStubsMap'.$stubsMapClassOriginalContent, - $contents, - ); -}; diff --git a/res/scoper-phpstorm-stubs.php b/res/scoper-phpstorm-stubs.php deleted file mode 100644 index 8ed329d0e..000000000 --- a/res/scoper-phpstorm-stubs.php +++ /dev/null @@ -1,49 +0,0 @@ - - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -use Isolated\Symfony\Component\Finder\Finder as IsolatedFinder; - -$jetBrainStubs = (static function (): array { - $files = []; - - foreach (new DirectoryIterator(__DIR__.'/../vendor/jetbrains/phpstorm-stubs') as $directoryInfo) { - if ($directoryInfo->isDot()) { - continue; - } - - if (false === $directoryInfo->isDir()) { - continue; - } - - if (in_array($directoryInfo->getBasename(), ['tests', 'meta'], true)) { - continue; - } - - foreach (new DirectoryIterator($directoryInfo->getPathName()) as $fileInfo) { - if ($fileInfo->isDot()) { - continue; - } - - if (1 !== preg_match('/\.php$/', $fileInfo->getBasename())) { - continue; - } - - $files[] = $fileInfo->getPathName(); - } - } - - return $files; -})(); - -return [...$jetBrainStubs]; diff --git a/res/scoper-polyfills.php b/res/scoper-polyfills.php deleted file mode 100644 index b69fbc829..000000000 --- a/res/scoper-polyfills.php +++ /dev/null @@ -1,42 +0,0 @@ - - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -use Isolated\Symfony\Component\Finder\Finder as IsolatedFinder; - -$polyfillsBootstraps = array_map( - static fn (SplFileInfo $fileInfo) => $fileInfo->getPathname(), - iterator_to_array( - IsolatedFinder::create() - ->files() - ->in(__DIR__ . '/../vendor/symfony/polyfill-*') - ->name('bootstrap*.php'), - false, - ), -); - -$polyfillsStubs = array_map( - static fn (SplFileInfo $fileInfo) => $fileInfo->getPathname(), - iterator_to_array( - IsolatedFinder::create() - ->files() - ->in(__DIR__ . '/../vendor/symfony/polyfill-*/Resources/stubs') - ->name('*.php'), - false, - ), -); - -return [ - ...$polyfillsBootstraps, - ...$polyfillsStubs, -]; diff --git a/scoper.inc.php b/scoper.inc.php index 008ad8fdf..73a8a55dd 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -14,15 +14,15 @@ use Isolated\Symfony\Component\Finder\Finder as IsolatedFinder; -$polyfillFiles = require __DIR__.'/res/scoper-polyfills.php'; -$jetBrainStubFiles = require __DIR__.'/res/scoper-phpstorm-stubs.php'; -$jetBrainStubPatcher = require __DIR__.'/res/scoper-phpstorm-stubs-map-patcher.php'; +$jetBrainStubs = (require __DIR__.'/vendor/humbug/php-scoper/res/get-scoper-phpstorm-stubs.php')( + __DIR__.'/vendor/jetbrains/phpstorm-stubs', +); +$jetBrainStubsPatcher = (require __DIR__.'/vendor/humbug/php-scoper/res/create-scoper-phpstorm-stubs-map-patcher.php')( + stubsMapPath: __DIR__.'/vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php', +); return [ - 'exclude-files' => [ - ...$polyfillFiles, - ...$jetBrainStubFiles, - ], + 'exclude-files' => $jetBrainStubs, 'exclude-namespaces' => [ 'Symfony\Polyfill' ], @@ -33,8 +33,11 @@ // Symfony global constants '/^SYMFONY\_[\p{L}_]+$/', ], - 'expose-functions' => [ - 'trigger_deprecation', + 'exclude-functions' => [ + // https://github.com/humbug/php-scoper/pull/894 + 'uv_poll_init_socket', + 'uv_signal_init', + 'uv_signal_start', ], 'expose-classes' => [ \Composer\Autoload\ClassLoader::class, @@ -45,6 +48,6 @@ \KevinGH\Box\Compactor\PhpScoper::class, ], 'patchers' => [ - $jetBrainStubPatcher, + $jetBrainStubsPatcher, ] ];