[+]: try to fix issue #942

copy&past from https://github.com/phan/phan/blob/master/src/Phan/Config/Initializer.php#L57 ;)
This commit is contained in:
Lars Moelleken 2019-01-11 15:11:35 +01:00
parent fe55bb3961
commit 5c7d983db6

View File

@ -1,6 +1,8 @@
<?php declare(strict_types=1);
$projectAutoload = getcwd() . '/vendor/autoload.php';
$cwd = getcwd();
$projectAutoload = $cwd . '/vendor/autoload.php';
if (is_file($projectAutoload)) {
require $projectAutoload;
}
@ -23,7 +25,29 @@ foreach ($possibleAutoloadPaths as $possibleAutoloadPath) {
}
}
die(sprintf(
$composer_json_path = $cwd . '/composer.json';
if (file_exists($composer_json_path)) {
$contents = file_get_contents($composer_json_path);
$composer_settings = json_decode($contents, true);
if (!is_array($composer_settings)) {
fwrite(STDERR, "Failed to load '$composer_json_path'\n");
return 1;
}
$vendor_path = $composer_settings['config']['vendor-dir'] ?? $cwd . '/vendor';
if (!is_dir($vendor_path)) {
fwrite(STDERR, "Please check if 'composer.phar install' was run already (expected to find '$vendor_path')\n");
return 1;
}
/** @noinspection PhpIncludeInspection */
require $vendor_path . '/autoload.php';
return;
}
fwrite(STDERR, sprintf(
'Composer autoload.php was not found in paths "%s". Have you ran "composer update"?',
implode('", "', $possibleAutoloadPaths)
));
exit(1);