forked from bitExpert/phpstan-magento
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoload.php
64 lines (56 loc) · 2.58 KB
/
autoload.php
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/*
* This file is part of the phpstan-magento package.
*
* (c) bitExpert AG
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use bitExpert\PHPStan\Magento\Autoload\Cache\FileCacheStorage;
use bitExpert\PHPStan\Magento\Autoload\FactoryAutoloader;
use bitExpert\PHPStan\Magento\Autoload\MockAutoloader;
use bitExpert\PHPStan\Magento\Autoload\ProxyAutoloader;
use bitExpert\PHPStan\Magento\Autoload\TestFrameworkAutoloader;
use Nette\Neon\Neon;
use PHPStan\Cache\Cache;
// This autoloader implementation supersedes the former \bitExpert\PHPStan\Magento\Autoload\Autoload implementation
(function (array $argv = []) {
// Sadly we don't have access to the parsed phpstan.neon configuration at this point we need to look up the
// location of the config file and parse it with the Neon parser to be able to extract the tmpDir definition!
$configFile = '';
if (count($argv) > 0) {
foreach($argv as $idx => $value) {
if ((strtolower($value) === '-c') && isset($argv[$idx + 1])) {
$configFile = $argv[$idx + 1];
break;
}
}
}
if (empty($configFile)) {
$currentWorkingDirectory = getcwd();
foreach (['phpstan.neon', 'phpstan.neon.dist'] as $discoverableConfigName) {
$discoverableConfigFile = $currentWorkingDirectory . DIRECTORY_SEPARATOR . $discoverableConfigName;
if (file_exists($discoverableConfigFile) && is_readable(($discoverableConfigFile))) {
$configFile = $discoverableConfigFile;
break;
}
}
}
$tmpDir = sys_get_temp_dir() . '/phpstan';
if (!empty($configFile)) {
$neonConfig = Neon::decode(file_get_contents($configFile));
if(is_array($neonConfig) && isset($neonConfig['parameters']) && isset($neonConfig['parameters']['tmpDir'])) {
$tmpDir = $neonConfig['parameters']['tmpDir'];
}
}
$cache = new Cache(new FileCacheStorage($tmpDir . '/cache/PHPStan'));
$mockAutoloader = new MockAutoloader();
$testFrameworkAutoloader = new TestFrameworkAutoloader();
$factoryAutoloader = new FactoryAutoloader($cache);
$proxyAutoloader = new ProxyAutoloader($cache);
\spl_autoload_register([$mockAutoloader, 'autoload'], true, true);
\spl_autoload_register([$testFrameworkAutoloader, 'autoload'], true, false);
\spl_autoload_register([$factoryAutoloader, 'autoload'], true, false);
\spl_autoload_register([$proxyAutoloader, 'autoload'], true, false);
})($GLOBALS['argv'] ?? []);