Skip to content

Commit

Permalink
WIP: continue the progress
Browse files Browse the repository at this point in the history
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
  • Loading branch information
theofidry committed Mar 3, 2018
1 parent 5a7028e commit 5d2301a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
7 changes: 5 additions & 2 deletions bin/box
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion src/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5d2301a

Please sign in to comment.