-
-
Notifications
You must be signed in to change notification settings - Fork 452
Expand file tree
/
Copy pathAutoloadFileParameterResolver.php
More file actions
38 lines (33 loc) · 1.31 KB
/
Copy pathAutoloadFileParameterResolver.php
File metadata and controls
38 lines (33 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace Rector\Bootstrap;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Symfony\Component\Console\Input\ArgvInput;
/**
* A different extra autoload changes what PHPStan can resolve, so cached results
* must not survive it. Registering the file as a parameter folds it into the
* configuration hash, which invalidates the cache like any other config change.
*
* Called from bin/rector.php before the configuration hash is computed.
*
* @see \Rector\Tests\Bootstrap\AutoloadFileParameterResolverTest
*/
final class AutoloadFileParameterResolver
{
/**
* @param array<int, mixed> $argv
*/
public static function resolveFromArgv(array $argv): void
{
// handles "--autoload-file path", "--autoload-file=path" and "-a path";
// parallel workers receive the space-separated form, so all spellings must
// normalize to the same value or main process and workers would disagree
$autoloadFile = new ArgvInput($argv)
->getParameterOption(['--autoload-file', '-a'], null);
if (! is_string($autoloadFile) || $autoloadFile === '') {
return;
}
SimpleParameterProvider::setParameter(Option::AUTOLOAD_FILE, realpath($autoloadFile) ?: $autoloadFile);
}
}