Skip to content

Commit f23b989

Browse files
committed
replaced Magento default autoloader with new one that checks files for existence
1 parent b6af7ad commit f23b989

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

extension.neon

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ parameters:
44
- */app/code/local/*/*/sql/*
55
bootstrapFiles:
66
- %currentWorkingDirectory%/htdocs/app/Mage.php
7-
- %currentWorkingDirectory%/vendor/vianetz/phpstan-magento1/phpstan-bootstrap.php
7+
- phpstan-bootstrap.php
8+
typeAliases:
9+
Mage_Catalog_Model_Entity_Product_Collection: 'Mage_Catalog_Model_Resource_Product_Collection'
810

911
services:
1012
-

phpstan-bootstrap.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,20 @@
77
(new ModuleControllerAutoloader('core'))->register();
88
(new ModuleControllerAutoloader('community'))->register();
99

10-
// workaround Magento's use of date phpdoc typehint for string type
11-
// better would be to implement the typehint to make it appear string type
12-
class date {}
10+
/**
11+
* We replace the original Varien_Autoload autoloader with a custom one.
12+
*/
13+
spl_autoload_register(static function($className) {
14+
spl_autoload_unregister([Varien_Autoload::instance(), 'autoload']);
15+
16+
$classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $className)));
17+
$classFile .= '.php';
18+
19+
foreach (explode(':', get_include_path()) as $path) {
20+
if (\file_exists($path . DIRECTORY_SEPARATOR . $classFile)) {
21+
return include $classFile;
22+
}
23+
}
24+
}, true, true);
1325

1426
Mage::app();

0 commit comments

Comments
 (0)