forked from ateli-development/phpstan-magento1
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathphpstan-bootstrap-mage-autoload.php
42 lines (34 loc) · 1.38 KB
/
phpstan-bootstrap-mage-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
<?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);
}
(new ModuleControllerAutoloader('local'))->register();
(new ModuleControllerAutoloader('core'))->register();
(new ModuleControllerAutoloader('community'))->register();
/**
* We replace the original Varien_Autoload autoloader with a custom one in order to prevent errors with invalid classes
* that are used throughout the Magento core code.
* The original autoloader would in this case return false and lead to an error in phpstan because the type alias in extension.neon
* is evaluated afterward.
*
* @see \Varien_Autoload::autoload()
*/
spl_autoload_register(static function ($className) {
spl_autoload_unregister([Varien_Autoload::instance(), 'autoload']);
$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);