From 5d2301a305656cbc83880636c3078d83dcd4a384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 3 Mar 2018 23:50:27 +0100 Subject: [PATCH] WIP: continue the progress There is a bug with the Composer namespace: - Either do not prefix any Composer related package - Either add an e2e test with Composer in PHP-Scoper --- bin/box | 7 +++++-- composer.lock | 10 +++++----- scoper.inc.php | 28 ++++++++++++++++++++++++++++ src/Box.php | 6 +++++- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/bin/box b/bin/box index b80e03219..060a3d430 100755 --- a/bin/box +++ b/bin/box @@ -21,10 +21,13 @@ use RuntimeException; $findAutoloader = function () { if (file_exists($autoload = __DIR__.'/../../../autoload.php')) { - // Is installed via composer + // Is installed via Composer + return $autoload; + } + if (file_exists($autoload = __DIR__.'/../vendor/scoper-autoload.php')) { + // Is scoped (in PHAR or dumped directory) return $autoload; } - if (file_exists($autoload = __DIR__.'/../vendor/autoload.php')) { // Is installed locally return $autoload; diff --git a/composer.lock b/composer.lock index c5410b6f7..83366f440 100644 --- a/composer.lock +++ b/composer.lock @@ -1080,16 +1080,16 @@ }, { "name": "nikic/php-parser", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "e57b3a09784f846411aa7ed664eedb73e3399078" + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/e57b3a09784f846411aa7ed664eedb73e3399078", - "reference": "e57b3a09784f846411aa7ed664eedb73e3399078", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", "shasum": "" }, "require": { @@ -1127,7 +1127,7 @@ "parser", "php" ], - "time": "2018-01-25T21:31:33+00:00" + "time": "2018-02-28T20:30:58+00:00" }, { "name": "ocramius/package-versions", diff --git a/scoper.inc.php b/scoper.inc.php index 3549a86cd..fd308710a 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -43,6 +43,34 @@ function (string $filePath, string $prefix, string $contents): string { $contents ); }, + function (string $filePath, string $prefix, string $contents): string { + $files = [ + 'src/functions.php', + 'src/Configuration.php', + ]; + + if (false === in_array($filePath, $files, true)) { + return $contents; + } + + $contents = preg_replace( + sprintf( + '/\\\\'.$prefix.'\\\\Herrera\\\\Box\\\\Compactor/', + $prefix + ), + '\\Herrera\\\Box\\Compactor', + $contents + ); + + return preg_replace( + sprintf( + '/\\\\'.$prefix.'\\\\KevinGH\\\\Box\\\\Compactor\\\\/', + $prefix + ), + '\\KevinGH\\\Box\\Compactor\\', + $contents + ); + }, ], 'whitelist' => [ \Herrera\Box\Compactor\Javascript::class, diff --git a/src/Box.php b/src/Box.php index 9e15dd116..5108f6405 100644 --- a/src/Box.php +++ b/src/Box.php @@ -252,8 +252,12 @@ public function addFile(string $file, string $contents = null, bool $binary = fa } if (is_debug_enabled()) { + if (false === $processedContents) { + $processedContents = $contents; + } + remove(self::DEBUG_DIR); // Cleanup previous temporary debug directory - copy($relativePath, self::DEBUG_DIR.'/'.$relativePath, true); + dump_file(self::DEBUG_DIR.DIRECTORY_SEPARATOR.$relativePath, $processedContents); } return $local;