From efe97a7d48169d01b776cdfb1d43608cad3f13c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Thu, 6 Jun 2019 00:48:16 +0200 Subject: [PATCH] Upgrade to PHP-Scoper 0.12 (#423) - Upgrade to PHP-Scoper 0.12 - Remove the pinned `roave/better-reflection` dependency (no longer necessary as the new Configuration works with the 3.5.0 version) - Upgrade to `nikic/iter` 2.0.0 which is compatible with the new PHP-Parser version and PHP 7.4.0 - Remove the Amphp related event loop extensions as it is no longer necessary to have them loaded for the scoping of their symbols to be done correctly - Update the PHP-Scoper config --- .travis.yml | 8 ------- .travis/install-ev.sh | 14 ------------- .travis/install-event.sh | 14 ------------- .travis/install-uv.sh | 28 ------------------------- composer.json | 5 ++--- scoper.inc.php | 19 +++-------------- src/Composer/ComposerOrchestrator.php | 2 +- src/Configuration/Configuration.php | 9 ++------ src/PhpScoper/SerializablePhpScoper.php | 2 +- 9 files changed, 9 insertions(+), 92 deletions(-) delete mode 100755 .travis/install-ev.sh delete mode 100755 .travis/install-event.sh delete mode 100755 .travis/install-uv.sh diff --git a/.travis.yml b/.travis.yml index 793b1fc17..bb54b5efb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,11 +15,6 @@ env: matrix: - COMPOSER_FLAGS='--no-interaction --no-progress --no-suggest --prefer-dist' -addons: - apt: - packages: - - libevent-dev - matrix: include: - php: '7.2' @@ -41,9 +36,6 @@ before_install: fi - set -eo pipefail - echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - - .travis/install-uv.sh - - .travis/install-ev.sh - - .travis/install-event.sh - composer validate - | if [ "DEPLOY" != "true" ]; then diff --git a/.travis/install-ev.sh b/.travis/install-ev.sh deleted file mode 100755 index 19fc006f5..000000000 --- a/.travis/install-ev.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -# -# Credits: https://github.com/amphp/amp/blob/8283532/travis/install-ev.sh -# - -curl -LS https://pecl.php.net/get/ev | tar -xz; -pushd ev-*; -phpize; -./configure; -make; -make install; -popd; -echo "extension=ev.so" >> "$(php -r 'echo php_ini_loaded_file();')"; \ No newline at end of file diff --git a/.travis/install-event.sh b/.travis/install-event.sh deleted file mode 100755 index 8fe91c54f..000000000 --- a/.travis/install-event.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -# -# Credits: https://github.com/amphp/amp/blob/8283532/travis/install-event.sh -# - -curl -LS https://pecl.php.net/get/event-2.3.0 | tar -xz \ - && pushd event-* \ - && phpize \ - && ./configure --with-event-core --with-event-extra --with-event-pthreads \ - && make \ - && make install \ - && popd \ - && echo "extension=event.so" >> "$(php -r 'echo php_ini_loaded_file();')"; diff --git a/.travis/install-uv.sh b/.travis/install-uv.sh deleted file mode 100755 index 37739c36e..000000000 --- a/.travis/install-uv.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -# -# Credits: https://github.com/amphp/amp/blob/8283532/travis/install-uv.sh -# - -wget https://github.com/libuv/libuv/archive/v1.x.tar.gz -O /tmp/libuv.tar.gz -q & -wget https://github.com/bwoebi/php-uv/archive/master.tar.gz -O /tmp/php-uv.tar.gz -q & -wait - -mkdir libuv && tar -xf /tmp/libuv.tar.gz -C libuv --strip-components=1 -mkdir php-uv && tar -xf /tmp/php-uv.tar.gz -C php-uv --strip-components=1 - -pushd libuv; -./autogen.sh -./configure --prefix=$(dirname `pwd`)/libuv-install -make -make install -popd - -pushd php-uv -phpize -./configure --with-uv=$(dirname `pwd`)/libuv-install -make -make install -popd - -echo "extension=uv.so" >> "$(php -r 'echo php_ini_loaded_file();')" diff --git a/composer.json b/composer.json index e6671ca74..1a3d965df 100644 --- a/composer.json +++ b/composer.json @@ -43,13 +43,12 @@ "ext-phar": "*", "amphp/parallel-functions": "^0.1.3", "beberlei/assert": "^3.2", - "roave/better-reflection": "~3.5.0", "composer/semver": "^1.5", "composer/xdebug-handler": "^1.3.2", "hoa/compiler": "^3.17", - "humbug/php-scoper": "~0.11", + "humbug/php-scoper": "~0.12", "justinrainbow/json-schema": "^5.2", - "nikic/iter": "^1.6", + "nikic/iter": "^2.0", "nikic/php-parser": "^4.2", "ocramius/package-versions": "^1.4", "opis/closure": "^3.2", diff --git a/scoper.inc.php b/scoper.inc.php index 3344f9ec1..4a04c1b36 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -106,7 +106,8 @@ static function (string $filePath, string $prefix, string $contents): string { return preg_replace( '/Hoa\\\\Consistency::registerShutdownFunction\(xcallable\(\'(.*)\'\)\)/', sprintf( - 'Hoa\\Consistency::registerShutdownFunction(xcallable(\'%s$1\'))', + 'Hoa\\Consistency::registerShutdownFunction(%sxcallable(\'%s$1\'))', + '\\\\'.$prefix.'\\\\', $prefix.'\\\\\\\\' ), $contents @@ -138,6 +139,7 @@ static function (string $filePath, string $prefix, string $contents): string { return $contents; }, + // Symfony polyfills patches static function (string $filePath, string $prefix, string $contents): string { if ('vendor/symfony/polyfill-php72/bootstrap.php' !== $filePath) { return $contents; @@ -151,8 +153,6 @@ static function (string $filePath, string $prefix, string $contents): string { }, ], 'whitelist' => [ - 'Composer\*', - \Composer\Autoload\ClassLoader::class, \KevinGH\Box\Compactor\Compactor::class, @@ -162,18 +162,6 @@ static function (string $filePath, string $prefix, string $contents): string { \KevinGH\Box\Compactor\Php::class, \KevinGH\Box\Compactor\PhpScoper::class, - // Symfony Polyfill for PHP 7.1 support - // https://github.com/humbug/php-scoper/issues/304 - 'sapi_windows_vt100_support', - 'stream_isatty', - 'utf8_encode', - 'utf8_decode', - 'spl_object_id', - 'PHP_OS_FAMILY', - 'mb_chr', - 'mb_ord', - 'mb_scrub', - // Hoa symbols 'SUCCEED', 'FAILED', @@ -203,7 +191,6 @@ static function (string $filePath, string $prefix, string $contents): string { '_concrete', '_overridable', 'WITH_COMPOSER', - 'xcallable', ], 'whitelist-global-constants' => false, 'whitelist-global-classes' => false, diff --git a/src/Composer/ComposerOrchestrator.php b/src/Composer/ComposerOrchestrator.php index 05085ffcd..441d1d2f0 100644 --- a/src/Composer/ComposerOrchestrator.php +++ b/src/Composer/ComposerOrchestrator.php @@ -81,7 +81,7 @@ private static function generateAutoloadStatements(Whitelist $whitelist, string $autoload ); - $whitelistStatements = (new ScoperAutoloadGenerator($whitelist))->dump($prefix); + $whitelistStatements = (new ScoperAutoloadGenerator($whitelist))->dump(); $whitelistStatements = preg_replace( '/scoper\-autoload\.php \@generated by PhpScoper/', diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index 0f016a3be..5f69ebbb0 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -39,7 +39,7 @@ use Herrera\Box\Compactor\Json as LegacyJson; use Herrera\Box\Compactor\Php as LegacyPhp; use Humbug\PhpScoper\Configuration as PhpScoperConfiguration; -use Humbug\PhpScoper\Console\ApplicationFactory; +use Humbug\PhpScoper\Container; use Humbug\PhpScoper\Scoper; use Humbug\PhpScoper\Scoper\FileWhitelistScoper; use function implode; @@ -2846,12 +2846,7 @@ static function (string $path) use ($basePath): string { $scoper = new SerializablePhpScoper( static function () use ($whitelistedFiles): Scoper { - $scoper = (new class() extends ApplicationFactory { - public static function createScoper(): Scoper - { - return parent::createScoper(); - } - })::createScoper(); + $scoper = (new Container())->getScoper(); if ([] !== $whitelistedFiles) { return new FileWhitelistScoper($scoper, ...$whitelistedFiles); diff --git a/src/PhpScoper/SerializablePhpScoper.php b/src/PhpScoper/SerializablePhpScoper.php index cbcad0ca7..717976f89 100644 --- a/src/PhpScoper/SerializablePhpScoper.php +++ b/src/PhpScoper/SerializablePhpScoper.php @@ -24,7 +24,7 @@ use function unserialize; /** - * Humbug PHP-Scoper scoper which leverages closures to ensure the scoper is serialiable. + * Humbug PHP-Scoper scoper which leverages closures to ensure the scoper is serializable. */ final class SerializablePhpScoper implements HumbugPhpScoperScoper, Serializable {