-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
phpstan-bootstrap.php
78 lines (62 loc) · 2.5 KB
/
phpstan-bootstrap.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
use staabm\PHPStanDba\QueryReflection\LazyQueryReflector;
use staabm\PHPStanDba\QueryReflection\PdoMysqlQueryReflector;
use staabm\PHPStanDba\QueryReflection\QueryReflection;
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
unset($REX);
$REX['REDAXO'] = true;
if (is_dir(__DIR__.'/../../../var/')) {
// yakamara directoy layout
$REX['HTDOCS_PATH'] = realpath(__DIR__.'/../../../');
require __DIR__ . '/../../../src/path_provider.php';
$REX['PATH_PROVIDER'] = new app_path_provider();
} else {
// default redaxo5 directory layout
$REX['HTDOCS_PATH'] = realpath(__DIR__.'/../../../../');
}
$REX['BACKEND_FOLDER'] = 'redaxo';
$REX['LOAD_PAGE'] = false;
require __DIR__.'/../../core/boot.php';
// boot addons to make rexstan aware of e.g. class registrations at boot time
include_once rex_path::core('packages.php');
// phpstan-dba bootstrapping
$reflectorFactory = static function (): PdoMysqlQueryReflector {
$configFile = rex_path::coreData('config.yml');
$config = rex_file::getConfig($configFile);
$db = ($config['db'][1] ?? []) + ['host' => '', 'login' => '', 'password' => '', 'name' => ''];
$pdo = new PDO(
sprintf('mysql:dbname=%s;host=%s', $db['name'], $db['host']),
$db['login'],
$db['password'],
);
return new PdoMysqlQueryReflector($pdo);
};
$config = new RuntimeConfiguration();
// $config->debugMode(true);
// $config->stringifyTypes(true);
// $config->analyzeQueryPlans(true);
$config->utilizeSqlAst(true);
QueryReflection::setupReflector(
new LazyQueryReflector($reflectorFactory),
$config
);
// on a git checkout require the root composer autoloader
// without also including static files (to prevent cannot re-declare function errors)
// to prevent errors like "Class XY extends unknown class PHPUnit\Framework\TestCase"
$basePath = rex_path::base();
if (is_file($basePath . '/vendor/autoload.php')) {
call_user_func(function () use ($basePath) {
$loader = new \Composer\Autoload\ClassLoader();
foreach (require $basePath . '/vendor/composer/autoload_namespaces.php' as $namespace => $path) {
$loader->set($namespace, $path);
}
foreach (require $basePath . '/vendor/composer/autoload_psr4.php' as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require $basePath . '/vendor/composer/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register(true);
});
}