Updated Rector to commit 4a583b6a777b38f14791374a8793f37ae024e6f9

4a583b6a77 [phpstan-extensions] Provide phpstan container to bootstrap file from extensions (#3401)
This commit is contained in:
Tomas Votruba 2023-02-23 09:42:39 +00:00
parent 3689432167
commit bfb3b0cf14
7 changed files with 32 additions and 17 deletions

View File

@ -60,6 +60,10 @@ final class PHPStanServicesFactory
$filesystem = new Filesystem();
$filesystem->remove($purifiedConfigFiles);
}
public function provideContainer() : Container
{
return $this->container;
}
/**
* @api
*/

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'b1b48bceab3cf56858ebe565a22bba74458a497f';
public const PACKAGE_VERSION = '4a583b6a777b38f14791374a8793f37ae024e6f9';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-02-22 18:44:57';
public const RELEASE_DATE = '2023-02-23 09:36:23';
/**
* @var int
*/

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Core\Autoloading;
use RectorPrefix202302\Nette\Neon\Neon;
use PHPStan\DependencyInjection\Container;
use Rector\Core\Configuration\Option;
use Rector\Core\Configuration\Parameter\ParameterProvider;
use Rector\Core\Exception\ShouldNotHappenException;
@ -33,12 +34,12 @@ final class BootstrapFilesIncluder
$this->parameterProvider = $parameterProvider;
$this->phpStanExtensionsConfigResolver = $phpStanExtensionsConfigResolver;
}
public function includePHPStanExtensionsBoostrapFiles() : void
public function includePHPStanExtensionsBoostrapFiles(?Container $container = null) : void
{
$extensionConfigFiles = $this->phpStanExtensionsConfigResolver->resolve();
$absoluteBootstrapFilePaths = $this->resolveAbsoluteBootstrapFilePaths($extensionConfigFiles);
foreach ($absoluteBootstrapFilePaths as $absoluteBootstrapFilePath) {
$this->tryRequireFile($absoluteBootstrapFilePath);
$this->tryRequireFile($absoluteBootstrapFilePath, $container);
}
}
/**
@ -79,10 +80,16 @@ final class BootstrapFilesIncluder
}
return $absoluteBootstrapFilePaths;
}
private function tryRequireFile(string $bootstrapFile) : void
/**
* PHPStan container mimics:
* https://github.com/phpstan/phpstan-src/blob/34881e682e36e30917dcfa8dc69c70e857143436/src/Command/CommandHelper.php#L513-L515
*/
private function tryRequireFile(string $bootstrapFile, ?Container $container = null) : void
{
try {
require_once $bootstrapFile;
(static function (string $bootstrapFile) use($container) : void {
require_once $bootstrapFile;
})($bootstrapFile);
} catch (Throwable $throwable) {
$errorMessage = \sprintf('"%s" thrown in "%s" on line %d while loading bootstrap file %s: %s', \get_class($throwable), $throwable->getFile(), $throwable->getLine(), $bootstrapFile, $throwable->getMessage());
throw new ShouldNotHappenException($errorMessage, $throwable->getCode(), $throwable);

View File

@ -8,6 +8,7 @@ use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\Core\Autoloading\BootstrapFilesIncluder;
use Rector\Core\Kernel\RectorKernel;
use Rector\Core\ValueObject\Bootstrap\BootstrapConfigs;
use Rector\NodeTypeResolver\DependencyInjection\PHPStanServicesFactory;
final class RectorContainerFactory
{
public function createFromBootstrapConfigs(BootstrapConfigs $bootstrapConfigs) : ContainerInterface
@ -22,7 +23,10 @@ final class RectorContainerFactory
/** @var BootstrapFilesIncluder $bootstrapFilesIncluder */
$bootstrapFilesIncluder = $container->get(BootstrapFilesIncluder::class);
$bootstrapFilesIncluder->includeBootstrapFiles();
$bootstrapFilesIncluder->includePHPStanExtensionsBoostrapFiles();
$phpStanServicesFactory = $container->get(PHPStanServicesFactory::class);
/** @var PHPStanServicesFactory $phpStanServicesFactory */
$phpStanContainer = $phpStanServicesFactory->provideContainer();
$bootstrapFilesIncluder->includePHPStanExtensionsBoostrapFiles($phpStanContainer);
return $container;
}
/**

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitcee583d2c4f8807da2eed5074c9c2a75::getLoader();
return ComposerAutoloaderInita0036db571e6f3784692d7da179c45bf::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitcee583d2c4f8807da2eed5074c9c2a75
class ComposerAutoloaderInita0036db571e6f3784692d7da179c45bf
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitcee583d2c4f8807da2eed5074c9c2a75
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitcee583d2c4f8807da2eed5074c9c2a75', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInita0036db571e6f3784692d7da179c45bf', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitcee583d2c4f8807da2eed5074c9c2a75', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInita0036db571e6f3784692d7da179c45bf', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitcee583d2c4f8807da2eed5074c9c2a75::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInita0036db571e6f3784692d7da179c45bf::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitcee583d2c4f8807da2eed5074c9c2a75::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInita0036db571e6f3784692d7da179c45bf::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitcee583d2c4f8807da2eed5074c9c2a75
class ComposerStaticInita0036db571e6f3784692d7da179c45bf
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3126,9 +3126,9 @@ class ComposerStaticInitcee583d2c4f8807da2eed5074c9c2a75
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitcee583d2c4f8807da2eed5074c9c2a75::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitcee583d2c4f8807da2eed5074c9c2a75::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitcee583d2c4f8807da2eed5074c9c2a75::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInita0036db571e6f3784692d7da179c45bf::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInita0036db571e6f3784692d7da179c45bf::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInita0036db571e6f3784692d7da179c45bf::$classMap;
}, null, ClassLoader::class);
}