php-scoper: PSR-0/4 dependencies are not correctly prefixed

Bug report

This is related to https://github.com/humbug/php-scoper/issues/127, but it feels like a regression has happened and now PSR-4 and PSR-0 namespaces aren’t prefixed in the Composer autoloader files.

Using the test repo here,

  • composer install
  • ./vendor/bin/php-scoper add-prefix --output-dir=build-prefixed --force --prefix=Mutant

autoload_static.php:

public static $prefixLengthsPsr4 = array(
		'S' => array(
			'Symfony\\Polyfill\\Php73\\'       => 23,
			'Symfony\\Polyfill\\Mbstring\\'    => 26,
			'Symfony\\Polyfill\\Ctype\\'       => 23,
			'Symfony\\Contracts\\Service\\'    => 26,
			'Symfony\\Component\\Finder\\'     => 25,
			'Symfony\\Component\\Filesystem\\' => 29,
			'Symfony\\Component\\Console\\'    => 26,
			'ScoperBug\\'                      => 10,
		),
		'P' => array(
			'Psr\\Container\\'  => 14,
			'PhpParser\\'       => 10,
			'PackageVersions\\' => 16,
		),
		'H' => array( 'Humbug\\PhpScoper\\' => 17 ),
	);
	public static $prefixDirsPsr4 = array(
		'Symfony\\Polyfill\\Php73\\'       => array( 0 => __DIR__ . '/..' . '/symfony/polyfill-php73' ),
		'Symfony\\Polyfill\\Mbstring\\'    => array( 0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring' ),
		'Symfony\\Polyfill\\Ctype\\'       => array( 0 => __DIR__ . '/..' . '/symfony/polyfill-ctype' ),
		'Symfony\\Contracts\\Service\\'    => array( 0 => __DIR__ . '/..' . '/symfony/service-contracts' ),
		'Symfony\\Component\\Finder\\'     => array( 0 => __DIR__ . '/..' . '/symfony/finder' ),
		'Symfony\\Component\\Filesystem\\' => array( 0 => __DIR__ . '/..' . '/symfony/filesystem' ),
		'Symfony\\Component\\Console\\'    => array( 0 => __DIR__ . '/..' . '/symfony/console' ),
		'ScoperBug\\'                      => array( 0 => __DIR__ . '/../..' . '/src' ),
		'Psr\\Container\\'                 => array( 0 => __DIR__ . '/..' . '/psr/container/src' ),
		'PhpParser\\'                      => array( 0 => __DIR__ . '/..' . '/nikic/php-parser/lib/PhpParser' ),
		'PackageVersions\\'                => array( 0 => __DIR__ . '/..' . '/ocramius/package-versions/src/PackageVersions' ),
		'Humbug\\PhpScoper\\'              => array( 0 => __DIR__ . '/..' . '/humbug/php-scoper/src' ),
	);
	public static $prefixesPsr0 = array( 'P' => array( 'Pimple' => array( 0 => __DIR__ . '/..' . '/pimple/pimple/src' ) ) );

The public static $classMap = array( is correctly prefixed

autoload_real.php

ClassLoader isn’t prefixed here -

    private static $loader;
    public static function loadClassLoader($class)
    {
        if ('Composer\\Autoload\\ClassLoader' === $class) {
            require __DIR__ . '/ClassLoader.php';
        }
    }

autoload_psr4.php

The array key strings of the class aren’t namespaced.

// autoload_psr4.php @generated by Composer
$vendorDir = \dirname( \dirname( __FILE__ ) );
$baseDir   = \dirname( $vendorDir );

return array( 'Symfony\\Polyfill\\Php73\\'       => array( $vendorDir . '/symfony/polyfill-php73' ),
              'Symfony\\Polyfill\\Mbstring\\'    => array( $vendorDir . '/symfony/polyfill-mbstring' ) );

autoload_namespaces.php

Same as autoload_psr4.php.

Question Answer
Box version 0.12.4 <!-- (php-scoper.phar -V or `composer show
PHP version 7.2.1
Platform with version MacOS
Github Repo https://github.com/polevaultweb/php-scoper-bug
scoper.inc.php
<?php

declare(strict_types=1);

use Isolated\Symfony\Component\Finder\Finder;

return [
];

Output
$ command
> output

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Either that, or we can try to find a way to do it in a more automated way. If you find a reproducible way to do it via a simple script for example, that could be enough and documented