mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 06:18:07 +01:00
resolve double autoload loading
This commit is contained in:
parent
8fda1339f1
commit
8a3bbec430
20
bin/build-prefixed-rector-bin.php
Normal file
20
bin/build-prefixed-rector-bin.php
Normal file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
|
||||
require_once __DIR__ . '/rector_bootstrap.php';
|
||||
|
||||
$binPath = __DIR__ . '/../build/bin/rector';
|
||||
|
||||
$binContent = file_get_contents($binPath);
|
||||
|
||||
// add constant to make clear the define('RECTOR_PREFIXED', true)
|
||||
$binContent = Strings::replace(
|
||||
$binContent,
|
||||
'#namespace RectorPrefixed;#',
|
||||
'namespace RectorPrefixed;' . PHP_EOL . "define('RECTOR_PREFIXED', true);"
|
||||
);
|
||||
|
||||
// save
|
||||
file_put_contents($binPath, $binContent);
|
@ -1,26 +1,24 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
$possibleAutoloadPaths = [
|
||||
// repository
|
||||
// dev repository
|
||||
__DIR__ . '/../vendor/autoload.php',
|
||||
// composer require
|
||||
__DIR__ . '/../../../../vendor/autoload.php',
|
||||
// load from nearest vendor
|
||||
getcwd() . '/vendor/autoload.php',
|
||||
];
|
||||
|
||||
$isAutoloadFileLoaded = false;
|
||||
// load the project with Prefixed Rector
|
||||
if (defined('RECTOR_PREFIXED')) {
|
||||
getcwd() . '/vendor/autoload.php';
|
||||
}
|
||||
|
||||
foreach ($possibleAutoloadPaths as $possibleAutoloadPath) {
|
||||
if (is_file($possibleAutoloadPath)) {
|
||||
require_once $possibleAutoloadPath;
|
||||
$isAutoloadFileLoaded = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isAutoloadFileLoaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
die(sprintf(
|
||||
'Composer autoload.php was not found in paths "%s". Have you ran "composer update"?',
|
||||
implode('", "', $possibleAutoloadPaths)
|
||||
|
Loading…
x
Reference in New Issue
Block a user