1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

ComposerAutoloaderInitXXX::getLoader behaves like a ClassLoader singleton

Calling ComposerAutoloaderInit::getLoader twice when a package requires a .php file containing functions, lead to the functions to be declared twice, and cause an error.

In my case, using behat + symfony2extension + assetic, the error that occured:

PHP Fatal error:  Cannot redeclare assetic_init() (previously declared in vendor/kriswallsmith/assetic/src/functions.php:20) in /vendor/kriswallsmith/assetic/src/functions.php on line 26

Fatal error: Cannot redeclare assetic_init() (previously declared in /vendor/kriswallsmith/assetic/src/functions.php:20) in /vendor/kriswallsmith/assetic/src/functions.php on line 26
This commit is contained in:
Adrien Brault 2012-09-14 11:21:34 +02:00
parent 02917bd892
commit fd58c24a9f
4 changed files with 28 additions and 4 deletions

View file

@ -6,9 +6,15 @@ require __DIR__ . '/ClassLoader.php';
class ComposerAutoloaderInitFilesAutoload
{
private static $loader;
public static function getLoader()
{
$loader = new \Composer\Autoload\ClassLoader();
if (null !== static::$loader) {
return static::$loader;
}
static::$loader = $loader = new \Composer\Autoload\ClassLoader();
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);