forked from ateli-development/phpstan-magento1
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathphpstan-bootstrap.php
59 lines (48 loc) · 1.69 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
<?php
declare(strict_types=1);
use PHPStanMagento1\Autoload\Magento\ModuleControllerAutoloader;
/**
* @var \PHPStan\DependencyInjection\MemoizingContainer $container
*/
$magentoRootPath = $container->getParameter('magentoRootPath');
if (empty($magentoRootPath)) {
throw new \Exception('Please set "magentoRootPath" in your phpstan.neon.');
}
if (!defined('BP')) {
define('BP', $magentoRootPath);
}
define('staticReflection', true);
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
if (!defined('PS')) {
define('PS', PATH_SEPARATOR);
}
/**
* Set include path
*/
$paths = [];
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
$paths[] = BP . DS . 'lib';
$appPath = implode(PS, $paths);
set_include_path($appPath . PS . get_include_path());
include_once 'Mage/Core/functions.php';
(new ModuleControllerAutoloader('local'))->register();
(new ModuleControllerAutoloader('core'))->register();
(new ModuleControllerAutoloader('community'))->register();
/**
* Custom autoloader compatible with Varien_Autoload
* Autoloading is needed only for the PHPStanMagento1\Config\MagentoCore which inherits from some magento classes.
* PHPStan uses static analysis, so doesn't require autoloading.
*/
spl_autoload_register(static function ($className) {
$classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $className)));
$classFile .= '.php';
foreach (explode(':', get_include_path()) as $path) {
if (\file_exists($path . DIRECTORY_SEPARATOR . $classFile)) {
return include $classFile;
}
}
}, true, true);