Skip to content

Commit

Permalink
Try to load composer from nearest vendor
Browse files Browse the repository at this point in the history
It will allow people to use phpstan globally just by adding their own autoload.php with the path they want inside.
  • Loading branch information
tyx committed Dec 26, 2016
1 parent 7173f92 commit 2b7cd12
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions bin/phpstan
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ use PHPStan\Command\AnalyseCommand;

gc_disable(); // performance boost

$composerAutoloadFile = __DIR__ . '/../vendor/autoload.php';
if (!is_file($composerAutoloadFile)) {
$composerAutoloadFile = __DIR__ . '/../../../autoload.php';
if (is_file($autoload = getcwd() . '/vendor/autoload.php')) {
require $autoload;
}

require_once($composerAutoloadFile);
if (!class_exists('PHPStan\Command\AnalyseCommand', true)) {
$composerAutoloadFile = __DIR__ . '/../vendor/autoload.php';
if (!is_file($composerAutoloadFile)) {
$composerAutoloadFile = __DIR__ . '/../../../autoload.php';
}

require_once($composerAutoloadFile);
}

$application = new \Symfony\Component\Console\Application('PHPStan - PHP Static Analysis Tool');
$application->setCatchExceptions(false);
Expand Down

0 comments on commit 2b7cd12

Please sign in to comment.