mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-30 14:43:31 +00:00
2.1 KiB
2.1 KiB
Static Reflection and Autoload
Rector is using static reflection to load code without running it since version 0.10. That means your classes are found without composer autoload and without running them. Rector will find them and work with them as you have PSR-4 autoload properly setup. This comes very useful in legacy projects or projects with custom autoload.
Do you want to know more about it? Continue here:
- From Doctrine Annotations Parser to Static Reflection
- Legacy Refactoring made Easy with Static Reflection
- Zero Config Analysis with Static Reflection - from PHPStan
// rector.php
use Rector\Core\Configuration\Option;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
// Rector is using static reflection to load code without running it - see https://phpstan.org/blog/zero-config-analysis-with-static-reflection
$parameters->set(Option::AUTOLOAD_PATHS, [
// discover specific file
__DIR__ . '/file-with-functions.php',
// or full directory
__DIR__ . '/project-without-composer',
]);
Include Files
Do you need to include constants, class aliases or custom autoloader? Use BOOTSTRAP_FILES
parameter:
// rector.php
use Rector\Core\Configuration\Option;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::BOOTSTRAP_FILES, [
__DIR__ . '/constants.php',
__DIR__ . '/project/special/autoload.php',
]);
};
Listed files will be executed like:
include $filePath;