2021-05-09 20:15:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2022-03-22 14:39:27 +00:00
|
|
|
// inspired by https://github.com/phpstan/phpstan/blob/master/bootstrap.php
|
|
|
|
spl_autoload_register(function (string $class): void {
|
|
|
|
static $composerAutoloader;
|
2021-05-09 20:15:43 +00:00
|
|
|
|
2022-03-22 14:39:27 +00:00
|
|
|
// already loaded in bin/rector.php
|
|
|
|
if (defined('__RECTOR_RUNNING__')) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
|
2022-03-22 14:39:27 +00:00
|
|
|
// load prefixed or native class, e.g. for running tests
|
|
|
|
if (strpos($class, 'RectorPrefix') === 0 || strpos($class, 'Rector\\') === 0) {
|
|
|
|
if ($composerAutoloader === null) {
|
|
|
|
// prefixed version autoload
|
|
|
|
$composerAutoloader = require __DIR__ . '/vendor/autoload.php';
|
2021-05-09 20:15:43 +00:00
|
|
|
}
|
2022-05-01 18:14:46 +00:00
|
|
|
|
|
|
|
// some weird collision with PHPStan custom rule tests
|
|
|
|
if (! is_int($composerAutoloader)) {
|
|
|
|
$composerAutoloader->loadClass($class);
|
|
|
|
}
|
2022-03-22 14:39:27 +00:00
|
|
|
}
|
|
|
|
});
|