2020-11-26 17:44:27 +01:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2021-12-14 08:14:22 +00:00
|
|
|
namespace RectorPrefix20211214;
|
2020-11-26 17:44:27 +01:00
|
|
|
|
2021-12-14 08:14:22 +00:00
|
|
|
use RectorPrefix20211214\Nette\Utils\Json;
|
2021-07-06 12:28:45 +00:00
|
|
|
use Rector\ChangesReporting\Output\JsonOutputFormatter;
|
2020-11-26 17:44:27 +01:00
|
|
|
use Rector\Core\Bootstrap\RectorConfigsResolver;
|
2021-07-06 12:28:45 +00:00
|
|
|
use Rector\Core\Configuration\Option;
|
2020-11-26 17:44:27 +01:00
|
|
|
use Rector\Core\Console\ConsoleApplication;
|
|
|
|
use Rector\Core\Console\Style\SymfonyStyleFactory;
|
|
|
|
use Rector\Core\DependencyInjection\RectorContainerFactory;
|
2021-11-01 14:32:25 +00:00
|
|
|
use Rector\Core\Kernel\RectorKernel;
|
2021-12-14 08:14:22 +00:00
|
|
|
use RectorPrefix20211214\Symfony\Component\Console\Command\Command;
|
|
|
|
use RectorPrefix20211214\Symfony\Component\Console\Input\ArgvInput;
|
|
|
|
use RectorPrefix20211214\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-12-14 08:14:22 +00:00
|
|
|
$autoloadIncluder = new \RectorPrefix20211214\AutoloadIncluder();
|
2020-11-26 17:44:27 +01:00
|
|
|
$autoloadIncluder->includeDependencyOrRepositoryVendorAutoloadIfExists();
|
2021-09-30 12:59:54 +00:00
|
|
|
if (\file_exists(__DIR__ . '/../preload.php') && \is_dir(__DIR__ . '/../vendor')) {
|
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-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) {
|
2021-07-06 12:28:45 +00:00
|
|
|
// for json output
|
2021-12-14 08:14:22 +00:00
|
|
|
$argvInput = new \RectorPrefix20211214\Symfony\Component\Console\Input\ArgvInput();
|
2021-07-06 12:28:45 +00:00
|
|
|
$outputFormat = $argvInput->getParameterOption('--' . \Rector\Core\Configuration\Option::OUTPUT_FORMAT);
|
|
|
|
// report fatal error in json format
|
|
|
|
if ($outputFormat === \Rector\ChangesReporting\Output\JsonOutputFormatter::NAME) {
|
2021-12-14 08:14:22 +00:00
|
|
|
echo \RectorPrefix20211214\Nette\Utils\Json::encode(['fatal_errors' => [$throwable->getMessage()]]);
|
2021-07-06 12:28:45 +00:00
|
|
|
} else {
|
|
|
|
// report fatal errors in console format
|
2021-12-14 08:14:22 +00:00
|
|
|
$symfonyStyleFactory = new \Rector\Core\Console\Style\SymfonyStyleFactory(new \RectorPrefix20211214\Symplify\PackageBuilder\Reflection\PrivatesCaller());
|
2021-07-06 12:28:45 +00:00
|
|
|
$symfonyStyle = $symfonyStyleFactory->create();
|
|
|
|
$symfonyStyle->error($throwable->getMessage());
|
|
|
|
}
|
2021-12-14 08:14:22 +00:00
|
|
|
exit(\RectorPrefix20211214\Symfony\Component\Console\Command\Command::FAILURE);
|
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-11-01 14:32:25 +00:00
|
|
|
if (\class_exists(\Rector\Core\Kernel\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-12-14 08:14:22 +00:00
|
|
|
\class_alias('RectorPrefix20211214\\AutoloadIncluder', 'AutoloadIncluder', \false);
|