From c7f092b635cb215a74ae81e4661c231153edaf24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 4 Nov 2023 21:46:49 +0100 Subject: [PATCH 1/3] build: Simplify the PHP-Scoper configuration - 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, ] ]; From 4b9c4ba1b065911d4b28634c1ee2679730ed7ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 4 Nov 2023 21:57:57 +0100 Subject: [PATCH 2/3] build: Remove unused extensions requirements and packages Closes #1118. Depends on #1146. --- composer.json | 3 -- composer.lock | 84 +++++---------------------------------------------- 2 files changed, 8 insertions(+), 79 deletions(-) diff --git a/composer.json b/composer.json index 6a1cf57e4..bb7adcc41 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,6 @@ "ext-iconv": "*", "ext-mbstring": "*", "ext-phar": "*", - "ext-sodium": "*", "composer-plugin-api": "^2.2", "amphp/parallel-functions": "^1.1", "composer/semver": "^3.3.2", @@ -33,7 +32,6 @@ "laravel/serializable-closure": "^1.2.2", "nikic/iter": "^2.2", "nikic/php-parser": "^4.15.2", - "paragonie/constant_time_encoding": "^2.6", "phpdocumentor/reflection-docblock": "^5.3", "phpdocumentor/type-resolver": "^1.7", "psr/log": "^3.0", @@ -61,7 +59,6 @@ "webmozarts/strict-phpunit": "^7.6" }, "replace": { - "paragonie/sodium_compat": "*", "symfony/polyfill-php80": "*", "symfony/polyfill-php81": "*" }, diff --git a/composer.lock b/composer.lock index 3481c4ecd..51444e388 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e176960d081e81e8d9426176dfe8ce49", + "content-hash": "50f25cdeee25a0f13d7e0d131c673111", "packages": [ { "name": "amphp/amp", @@ -977,16 +977,16 @@ }, { "name": "humbug/php-scoper", - "version": "0.18.6", + "version": "0.18.7", "source": { "type": "git", "url": "https://github.com/humbug/php-scoper.git", - "reference": "e5a152c0f40c6cf7994fb27f14e50e47d7c4c4ff" + "reference": "9386a0af946f175d7a1ebfb68851bc2bb8ad7858" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/humbug/php-scoper/zipball/e5a152c0f40c6cf7994fb27f14e50e47d7c4c4ff", - "reference": "e5a152c0f40c6cf7994fb27f14e50e47d7c4c4ff", + "url": "https://api.github.com/repos/humbug/php-scoper/zipball/9386a0af946f175d7a1ebfb68851bc2bb8ad7858", + "reference": "9386a0af946f175d7a1ebfb68851bc2bb8ad7858", "shasum": "" }, "require": { @@ -1004,7 +1004,7 @@ "bamarni/composer-bin-plugin": "^1.1", "ergebnis/composer-normalize": "^2.28", "fidry/makefile": "^1.0", - "humbug/box": "^4.0", + "humbug/box": "^4.5.1", "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^9.0", "symfony/yaml": "^6.1" @@ -1054,9 +1054,9 @@ "description": "Prefixes all PHP namespaces in a file or directory.", "support": { "issues": "https://github.com/humbug/php-scoper/issues", - "source": "https://github.com/humbug/php-scoper/tree/0.18.6" + "source": "https://github.com/humbug/php-scoper/tree/0.18.7" }, - "time": "2023-11-04T16:43:20+00:00" + "time": "2023-11-04T18:01:12+00:00" }, { "name": "jetbrains/phpstorm-stubs", @@ -1344,73 +1344,6 @@ }, "time": "2023-08-13T19:53:39+00:00" }, - { - "name": "paragonie/constant_time_encoding", - "version": "v2.6.3", - "source": { - "type": "git", - "url": "https://github.com/paragonie/constant_time_encoding.git", - "reference": "58c3f47f650c94ec05a151692652a868995d2938" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/58c3f47f650c94ec05a151692652a868995d2938", - "reference": "58c3f47f650c94ec05a151692652a868995d2938", - "shasum": "" - }, - "require": { - "php": "^7|^8" - }, - "require-dev": { - "phpunit/phpunit": "^6|^7|^8|^9", - "vimeo/psalm": "^1|^2|^3|^4" - }, - "type": "library", - "autoload": { - "psr-4": { - "ParagonIE\\ConstantTime\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Paragon Initiative Enterprises", - "email": "security@paragonie.com", - "homepage": "https://paragonie.com", - "role": "Maintainer" - }, - { - "name": "Steve 'Sc00bz' Thomas", - "email": "steve@tobtu.com", - "homepage": "https://www.tobtu.com", - "role": "Original Developer" - } - ], - "description": "Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)", - "keywords": [ - "base16", - "base32", - "base32_decode", - "base32_encode", - "base64", - "base64_decode", - "base64_encode", - "bin2hex", - "encoding", - "hex", - "hex2bin", - "rfc4648" - ], - "support": { - "email": "info@paragonie.com", - "issues": "https://github.com/paragonie/constant_time_encoding/issues", - "source": "https://github.com/paragonie/constant_time_encoding" - }, - "time": "2022-06-14T06:56:20+00:00" - }, { "name": "phpdocumentor/reflection-common", "version": "2.2.0", @@ -5778,7 +5711,6 @@ "ext-iconv": "*", "ext-mbstring": "*", "ext-phar": "*", - "ext-sodium": "*", "composer-plugin-api": "^2.2" }, "platform-dev": [], From 7996fff7886874c01cbf2fc7d4f25094bcc7d0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 5 Nov 2023 20:10:16 +0100 Subject: [PATCH 3/3] remove obsolete dep --- src/Console/Command/Extract.php | 4 ++-- src/Phar/PharInfo.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Console/Command/Extract.php b/src/Console/Command/Extract.php index bf37e1f6d..bae280a42 100644 --- a/src/Console/Command/Extract.php +++ b/src/Console/Command/Extract.php @@ -22,11 +22,11 @@ use KevinGH\Box\Phar\InvalidPhar; use KevinGH\Box\Phar\PharFactory; use KevinGH\Box\Phar\PharMeta; -use ParagonIE\ConstantTime\Hex; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Question\ConfirmationQuestion; use Throwable; +use function bin2hex; use function file_exists; use function KevinGH\Box\check_php_settings; use function realpath; @@ -188,7 +188,7 @@ private static function generateAlias(string $file): string { $extension = self::getExtension($file); - return Hex::encode(random_bytes(16)).$extension; + return bin2hex(random_bytes(16)).$extension; } private static function getExtension(string $file): string diff --git a/src/Phar/PharInfo.php b/src/Phar/PharInfo.php index b0d5baa2e..ed10a7e0a 100644 --- a/src/Phar/PharInfo.php +++ b/src/Phar/PharInfo.php @@ -46,7 +46,6 @@ use Fidry\FileSystem\FS; use KevinGH\Box\Console\Command\Extract; use OutOfBoundsException; -use ParagonIE\ConstantTime\Hex; use Phar; use RuntimeException; use Symfony\Component\Filesystem\Path; @@ -55,6 +54,7 @@ use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; +use function bin2hex; use function file_exists; use function getenv; use function is_readable; @@ -280,7 +280,7 @@ private static function initAlgorithms(): void private static function initStubFileName(): void { if (!isset(self::$stubfile)) { - self::$stubfile = Hex::encode(random_bytes(12)).'.pharstub'; + self::$stubfile = bin2hex(random_bytes(12)).'.pharstub'; } }