Skip to content

Commit a28a3cc

Browse files
committed
Fix autoloader collisions on scoped files
1 parent bf1d39b commit a28a3cc

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-15
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
],
3535
"prefix-dependencies": [
3636
"vendor/bin/php-scoper add-prefix --output-dir=./vendor-build --force --quiet",
37-
"COMPOSER_VENDOR_DIR=vendor-build composer dump-autoload"
37+
"COMPOSER_VENDOR_DIR=vendor-build composer dump-autoload",
38+
"php scoper.fix.php"
3839
]
3940
}
4041
}

scoper.fix.php

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

vendor-build/composer/autoload_files.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
$baseDir = dirname($vendorDir);
77

88
return array(
9-
'7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php',
10-
'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php',
11-
'6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
12-
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
13-
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
14-
'b067bc7112e384b61c701452d53a14a8' => $vendorDir . '/mtdowling/jmespath.php/src/JmesPath.php',
15-
'8a9dc1de0ca7e01f3e08231539562f61' => $vendorDir . '/aws/aws-sdk-php/src/functions.php',
9+
'a7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php',
10+
'ac964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php',
11+
'a6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
12+
'a0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
13+
'a37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
14+
'ab067bc7112e384b61c701452d53a14a8' => $vendorDir . '/mtdowling/jmespath.php/src/JmesPath.php',
15+
'a8a9dc1de0ca7e01f3e08231539562f61' => $vendorDir . '/aws/aws-sdk-php/src/functions.php',
1616
);

vendor-build/composer/autoload_static.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
class ComposerStaticInit06f9fe8c7bfa814a66af7f31c67c0eda
88
{
99
public static $files = array (
10-
'7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php',
11-
'c964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php',
12-
'6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',
13-
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
14-
'37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
15-
'b067bc7112e384b61c701452d53a14a8' => __DIR__ . '/..' . '/mtdowling/jmespath.php/src/JmesPath.php',
16-
'8a9dc1de0ca7e01f3e08231539562f61' => __DIR__ . '/..' . '/aws/aws-sdk-php/src/functions.php',
10+
'a7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php',
11+
'ac964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php',
12+
'a6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',
13+
'a0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
14+
'a37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
15+
'ab067bc7112e384b61c701452d53a14a8' => __DIR__ . '/..' . '/mtdowling/jmespath.php/src/JmesPath.php',
16+
'a8a9dc1de0ca7e01f3e08231539562f61' => __DIR__ . '/..' . '/aws/aws-sdk-php/src/functions.php',
1717
);
1818

1919
public static $prefixLengthsPsr4 = array (

0 commit comments

Comments
 (0)