Last active
November 28, 2019 15:24
-
-
Save polevaultweb/de44d747b57191a851947d5f5175e922 to your computer and use it in GitHub Desktop.
Patch file to run after PHP Scoper to ensure the Composer Autoload namespace is prefixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Make sure the Composer\Autoload namespace is prefixed. | |
* Needs to be run after php-scoper. | |
* | |
* `php ./patch-scoper-autoloader-namespace.php MY_PREFIX` | |
*/ | |
if ( empty( $argv[1] ) ) { | |
return; | |
} | |
$prefix = $argv[1]; | |
$scoper_path = './build/vendor/composer'; | |
prefix_namespace_in_autoloader_file( $scoper_path . '/autoload_static.php', $prefix ); | |
prefix_namespace_in_autoloader_file( $scoper_path . '/autoload_real.php', $prefix ); | |
prefix_namespace_in_autoloader_file( $scoper_path . '/ClassLoader.php', $prefix ); | |
function prefix_namespace_in_autoloader_file( $file, $prefix ) { | |
$path = $file; | |
$contents = file_get_contents( $path ); | |
$contents = str_replace( 'Composer\Autoload', $prefix . '\Composer\Autoload', $contents ); | |
file_put_contents( $path, $contents ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment