Skip to content
This repository was archived by the owner on Dec 9, 2019. It is now read-only.

Commit fd38d22

Browse files
committed
Introduce the bootstrap with a different autoloader again
1 parent 26cbdbf commit fd38d22

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

bootstrap.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types = 1);
2+
3+
spl_autoload_register(function (string $class): void {
4+
if (!extension_loaded('phar') || defined('__PHPSTAN_RUNNING__')) {
5+
return;
6+
}
7+
8+
if (strpos($class, '_HumbugBox') === 0) {
9+
if (!in_array('phar', stream_get_wrappers(), true)) {
10+
throw new \Exception('Phar wrapper is not registered. Please review your php.ini settings.');
11+
}
12+
13+
$composerAutoloader = require 'phar://' . __DIR__ . '/phpstan.phar/vendor/autoload.php';
14+
$composerAutoloader->loadClass($class);
15+
16+
return;
17+
}
18+
if (strpos($class, 'PHPStan\\PhpDocParser\\') === 0) {
19+
return;
20+
}
21+
if (strpos($class, 'PHPStan\\') !== 0) {
22+
return;
23+
}
24+
25+
if (!in_array('phar', stream_get_wrappers(), true)) {
26+
throw new \Exception('Phar wrapper is not registered. Please review your php.ini settings.');
27+
}
28+
29+
$filename = str_replace('\\', DIRECTORY_SEPARATOR, $class);
30+
$filename = substr($filename, strlen('PHPStan\\'));
31+
$filepath = 'phar://' . __DIR__ . '/phpstan.phar/src/' . $filename . '.php';
32+
if (!file_exists($filepath)) {
33+
return;
34+
}
35+
36+
require $filepath;
37+
});

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@
1717
"branch-alias": {
1818
"dev-master": "0.12-dev"
1919
}
20+
},
21+
"autoload": {
22+
"files": ["bootstrap.php"]
2023
}
2124
}

0 commit comments

Comments
 (0)