Skip to content

Instantly share code, notes, and snippets.

@polevaultweb
Last active November 28, 2019 15:24
Show Gist options
  • Save polevaultweb/de44d747b57191a851947d5f5175e922 to your computer and use it in GitHub Desktop.
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
<?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