2020-11-26 17:44:27 +01:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2021-07-06 08:19:07 +00:00
|
|
|
namespace RectorPrefix20210706;
|
2020-11-26 17:44:27 +01:00
|
|
|
|
|
|
|
use Rector\Core\Bootstrap\RectorConfigsResolver;
|
|
|
|
use Rector\Core\Console\ConsoleApplication;
|
|
|
|
use Rector\Core\Console\Style\SymfonyStyleFactory;
|
|
|
|
use Rector\Core\DependencyInjection\RectorContainerFactory;
|
2020-11-27 17:32:38 +01:00
|
|
|
use Rector\Core\HttpKernel\RectorKernel;
|
2021-07-06 08:19:07 +00:00
|
|
|
use RectorPrefix20210706\Symplify\PackageBuilder\Console\ShellCode;
|
|
|
|
use RectorPrefix20210706\Symplify\PackageBuilder\Reflection\PrivatesCaller;
|
2020-11-26 17:44:27 +01:00
|
|
|
// @ intentionally: continue anyway
|
2021-05-09 20:15:43 +00:00
|
|
|
@\ini_set('memory_limit', '-1');
|
2020-11-26 17:44:27 +01:00
|
|
|
// Performance boost
|
2021-05-09 20:15:43 +00:00
|
|
|
\error_reporting(\E_ALL);
|
|
|
|
\ini_set('display_errors', 'stderr');
|
|
|
|
\gc_disable();
|
|
|
|
\define('__RECTOR_RUNNING__', \true);
|
2020-11-26 17:44:27 +01:00
|
|
|
// Require Composer autoload.php
|
2021-07-06 08:19:07 +00:00
|
|
|
$autoloadIncluder = new \RectorPrefix20210706\AutoloadIncluder();
|
2020-11-26 17:44:27 +01:00
|
|
|
$autoloadIncluder->includeDependencyOrRepositoryVendorAutoloadIfExists();
|
2021-05-06 23:43:45 +02:00
|
|
|
// load extracted PHPStan with its own preload.php
|
|
|
|
$extractedPhpstanAutoload = __DIR__ . '/../vendor/phpstan/phpstan-extracted/vendor/autoload.php';
|
2021-05-09 20:15:43 +00:00
|
|
|
if (\file_exists($extractedPhpstanAutoload)) {
|
2021-05-06 23:43:45 +02:00
|
|
|
require_once $extractedPhpstanAutoload;
|
2021-07-06 08:19:07 +00:00
|
|
|
} elseif (\RectorPrefix20210706\should_include_preload()) {
|
2021-05-04 18:49:15 +07:00
|
|
|
require_once __DIR__ . '/../preload.php';
|
|
|
|
}
|
2021-05-04 14:21:34 +02:00
|
|
|
require_once __DIR__ . '/../src/constants.php';
|
2020-12-26 00:17:31 +01:00
|
|
|
$autoloadIncluder->loadIfExistsAndNotLoadedYet(__DIR__ . '/../vendor/scoper-autoload.php');
|
|
|
|
$autoloadIncluder->autoloadProjectAutoloaderFile();
|
2020-11-26 17:44:27 +01:00
|
|
|
$autoloadIncluder->autoloadFromCommandLine();
|
2021-07-06 08:19:07 +00:00
|
|
|
$symfonyStyleFactory = new \Rector\Core\Console\Style\SymfonyStyleFactory(new \RectorPrefix20210706\Symplify\PackageBuilder\Reflection\PrivatesCaller());
|
2020-11-26 17:44:27 +01:00
|
|
|
$symfonyStyle = $symfonyStyleFactory->create();
|
2021-05-10 22:23:08 +00:00
|
|
|
$rectorConfigsResolver = new \Rector\Core\Bootstrap\RectorConfigsResolver();
|
2020-11-26 17:44:27 +01:00
|
|
|
try {
|
2021-02-20 20:48:04 +01:00
|
|
|
$bootstrapConfigs = $rectorConfigsResolver->provide();
|
2021-05-10 22:23:08 +00:00
|
|
|
$rectorContainerFactory = new \Rector\Core\DependencyInjection\RectorContainerFactory();
|
2021-02-20 20:48:04 +01:00
|
|
|
$container = $rectorContainerFactory->createFromBootstrapConfigs($bootstrapConfigs);
|
2021-05-09 20:15:43 +00:00
|
|
|
} catch (\Throwable $throwable) {
|
2020-11-26 17:44:27 +01:00
|
|
|
$symfonyStyle->error($throwable->getMessage());
|
2021-07-06 08:19:07 +00:00
|
|
|
exit(\RectorPrefix20210706\Symplify\PackageBuilder\Console\ShellCode::ERROR);
|
2020-11-26 17:44:27 +01:00
|
|
|
}
|
|
|
|
/** @var ConsoleApplication $application */
|
2021-05-10 22:23:08 +00:00
|
|
|
$application = $container->get(\Rector\Core\Console\ConsoleApplication::class);
|
2020-11-26 17:44:27 +01:00
|
|
|
exit($application->run());
|
|
|
|
final class AutoloadIncluder
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*/
|
|
|
|
private $alreadyLoadedAutoloadFiles = [];
|
2021-05-09 20:15:43 +00:00
|
|
|
public function includeDependencyOrRepositoryVendorAutoloadIfExists() : void
|
2020-11-26 17:44:27 +01:00
|
|
|
{
|
|
|
|
// Rector's vendor is already loaded
|
2021-05-10 22:23:08 +00:00
|
|
|
if (\class_exists(\Rector\Core\HttpKernel\RectorKernel::class)) {
|
2020-11-26 17:44:27 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-11-27 21:00:10 +00:00
|
|
|
// in Rector develop repository
|
|
|
|
$this->loadIfExistsAndNotLoadedYet(__DIR__ . '/../vendor/autoload.php');
|
2020-11-26 17:44:27 +01:00
|
|
|
}
|
|
|
|
/**
|
2020-11-27 21:00:10 +00:00
|
|
|
* In case Rector is installed as vendor dependency,
|
|
|
|
* this autoloads the project vendor/autoload.php, including Rector
|
2020-11-26 17:44:27 +01:00
|
|
|
*/
|
2021-05-09 20:15:43 +00:00
|
|
|
public function autoloadProjectAutoloaderFile() : void
|
2020-11-26 17:44:27 +01:00
|
|
|
{
|
2021-03-04 15:02:07 +01:00
|
|
|
$this->loadIfExistsAndNotLoadedYet(__DIR__ . '/../../../autoload.php');
|
2020-11-26 17:44:27 +01:00
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
public function autoloadFromCommandLine() : void
|
2020-11-26 17:44:27 +01:00
|
|
|
{
|
|
|
|
$cliArgs = $_SERVER['argv'];
|
2021-05-09 20:15:43 +00:00
|
|
|
$autoloadOptionPosition = \array_search('-a', $cliArgs, \true) ?: \array_search('--autoload-file', $cliArgs, \true);
|
|
|
|
if (!$autoloadOptionPosition) {
|
2020-11-26 17:44:27 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$autoloadFileValuePosition = $autoloadOptionPosition + 1;
|
|
|
|
$fileToAutoload = $cliArgs[$autoloadFileValuePosition] ?? null;
|
|
|
|
if ($fileToAutoload === null) {
|
|
|
|
return;
|
|
|
|
}
|
2020-11-27 21:00:10 +00:00
|
|
|
$this->loadIfExistsAndNotLoadedYet($fileToAutoload);
|
2020-11-26 17:44:27 +01:00
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
public function loadIfExistsAndNotLoadedYet(string $filePath) : void
|
2020-11-26 17:44:27 +01:00
|
|
|
{
|
2021-05-09 20:15:43 +00:00
|
|
|
if (!\file_exists($filePath)) {
|
2020-11-26 17:44:27 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
if (\in_array($filePath, $this->alreadyLoadedAutoloadFiles, \true)) {
|
2020-11-27 21:00:10 +00:00
|
|
|
return;
|
2020-11-26 17:44:27 +01:00
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
$this->alreadyLoadedAutoloadFiles[] = \realpath($filePath);
|
2020-12-24 23:01:30 +01:00
|
|
|
require_once $filePath;
|
2020-11-26 17:44:27 +01:00
|
|
|
}
|
|
|
|
}
|
2021-07-06 08:19:07 +00:00
|
|
|
\class_alias('RectorPrefix20210706\\AutoloadIncluder', 'AutoloadIncluder', \false);
|
2021-05-04 14:21:34 +02:00
|
|
|
// load local php-parser only in prefixed version or development repository
|
2021-05-09 20:15:43 +00:00
|
|
|
function should_include_preload() : bool
|
2021-05-04 14:21:34 +02:00
|
|
|
{
|
2021-05-09 20:15:43 +00:00
|
|
|
if (\file_exists(__DIR__ . '/../vendor/scoper-autoload.php')) {
|
|
|
|
return \true;
|
2021-05-04 14:21:34 +02:00
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
if (!\file_exists(\getcwd() . '/composer.json')) {
|
|
|
|
return \false;
|
2021-05-04 14:21:34 +02:00
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
$composerJsonFileContent = \file_get_contents(\getcwd() . '/composer.json');
|
|
|
|
return \strpos($composerJsonFileContent, '"name": "rector/rector"') !== \false;
|
2021-05-04 14:21:34 +02:00
|
|
|
}
|