resolve double autoload loading

This commit is contained in:
Tomas Votruba 2018-05-28 17:34:39 +02:00
parent 8fda1339f1
commit 8a3bbec430
2 changed files with 27 additions and 9 deletions

View 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);

View File

@ -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)