Skip to content

Commit

Permalink
Fix autoloader collisions on scoped files
Browse files Browse the repository at this point in the history
  • Loading branch information
bryannielsen committed Sep 1, 2022
1 parent bf1d39b commit a28a3cc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
],
"prefix-dependencies": [
"vendor/bin/php-scoper add-prefix --output-dir=./vendor-build --force --quiet",
"COMPOSER_VENDOR_DIR=vendor-build composer dump-autoload"
"COMPOSER_VENDOR_DIR=vendor-build composer dump-autoload",
"php scoper.fix.php"
]
}
}
27 changes: 27 additions & 0 deletions scoper.fix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
*
* PHP-Scoper also can not handle Composers static file autoloaders.
* This is due to Composer loading files based on a hash which is generated from package name and relative file path.
* For a workaround see #298. https://github.com/humbug/php-scoper/blob/master/docs/limitations.md#composer-autoloader
*
* Script taken from https://github.com/humbug/php-scoper/issues/298#issuecomment-525700081
*
* This helper is needed to "trick" composer autoloader to load the prefixed files
* Otherwise if a dependency contains the same libraries ( i.e. guzzle ) it won't
* load the files, as the file hash is the same and thus composer would think this was already loaded
*
* More information also found here: https://github.com/humbug/php-scoper/issues/298
*/
$composer_path = './vendor-build/composer';
$static_loader_path = $composer_path . '/autoload_static.php';
echo "Fixing $static_loader_path \n";
$static_loader = file_get_contents($static_loader_path);
$static_loader = \preg_replace('/\'([A-Za-z0-9]*?)\' => __DIR__ \. (.*?),/', '\'a$1\' => __DIR__ . $2,', $static_loader);
file_put_contents($static_loader_path, $static_loader);
$files_loader_path = $composer_path . '/autoload_files.php';
echo "Fixing $files_loader_path \n";
$files_loader = file_get_contents($files_loader_path);
$files_loader = \preg_replace('/\'(.*?)\' => (.*?),/', '\'a$1\' => $2,', $files_loader);
file_put_contents($files_loader_path, $files_loader);
14 changes: 7 additions & 7 deletions vendor-build/composer/autoload_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
$baseDir = dirname($vendorDir);

return array(
'7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php',
'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php',
'6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
'b067bc7112e384b61c701452d53a14a8' => $vendorDir . '/mtdowling/jmespath.php/src/JmesPath.php',
'8a9dc1de0ca7e01f3e08231539562f61' => $vendorDir . '/aws/aws-sdk-php/src/functions.php',
'a7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php',
'ac964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php',
'a6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
'a0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
'a37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
'ab067bc7112e384b61c701452d53a14a8' => $vendorDir . '/mtdowling/jmespath.php/src/JmesPath.php',
'a8a9dc1de0ca7e01f3e08231539562f61' => $vendorDir . '/aws/aws-sdk-php/src/functions.php',
);
14 changes: 7 additions & 7 deletions vendor-build/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
class ComposerStaticInit06f9fe8c7bfa814a66af7f31c67c0eda
{
public static $files = array (
'7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php',
'c964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php',
'6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
'b067bc7112e384b61c701452d53a14a8' => __DIR__ . '/..' . '/mtdowling/jmespath.php/src/JmesPath.php',
'8a9dc1de0ca7e01f3e08231539562f61' => __DIR__ . '/..' . '/aws/aws-sdk-php/src/functions.php',
'a7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php',
'ac964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php',
'a6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',
'a0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
'a37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
'ab067bc7112e384b61c701452d53a14a8' => __DIR__ . '/..' . '/mtdowling/jmespath.php/src/JmesPath.php',
'a8a9dc1de0ca7e01f3e08231539562f61' => __DIR__ . '/..' . '/aws/aws-sdk-php/src/functions.php',
);

public static $prefixLengthsPsr4 = array (
Expand Down

0 comments on commit a28a3cc

Please sign in to comment.