2018-06-13 10:33:45 +02:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
2019-08-29 22:44:30 +02:00
|
|
|
use Rector\Console\Option\SetOptionResolver;
|
|
|
|
use Rector\Exception\Configuration\SetNotFoundException;
|
2019-02-23 00:08:58 +01:00
|
|
|
use Rector\HttpKernel\RectorKernel;
|
2018-06-13 10:33:45 +02:00
|
|
|
use Symfony\Component\Console\Input\ArgvInput;
|
|
|
|
use Symplify\PackageBuilder\Configuration\ConfigFileFinder;
|
2019-02-23 00:08:58 +01:00
|
|
|
use Symplify\PackageBuilder\Console\Input\InputDetector;
|
2019-06-01 11:46:18 +03:00
|
|
|
use Symplify\PackageBuilder\Console\ShellCode;
|
|
|
|
use Symplify\PackageBuilder\Console\Style\SymfonyStyleFactory;
|
2018-06-13 10:33:45 +02:00
|
|
|
|
2018-08-30 11:33:52 +02:00
|
|
|
$configFiles = [];
|
2018-06-13 10:33:45 +02:00
|
|
|
|
2019-08-29 22:44:30 +02:00
|
|
|
// Detect configuration from --set
|
2019-06-01 11:46:18 +03:00
|
|
|
try {
|
2019-08-29 22:44:30 +02:00
|
|
|
$configFiles[] = (new SetOptionResolver())->detectFromInputAndDirectory(
|
2019-06-01 11:46:18 +03:00
|
|
|
new ArgvInput(),
|
2019-06-08 22:41:52 +02:00
|
|
|
__DIR__ . '/../config/set'
|
2019-06-01 11:46:18 +03:00
|
|
|
);
|
2019-08-29 22:44:30 +02:00
|
|
|
} catch (SetNotFoundException $setNotFoundException) {
|
2019-06-01 11:46:18 +03:00
|
|
|
$symfonyStyle = (new SymfonyStyleFactory())->create();
|
2019-08-29 22:44:30 +02:00
|
|
|
$symfonyStyle->error($setNotFoundException->getMessage());
|
2019-06-01 11:46:18 +03:00
|
|
|
exit(ShellCode::ERROR);
|
|
|
|
}
|
2018-08-30 11:33:52 +02:00
|
|
|
|
|
|
|
// And from --config or default one
|
|
|
|
ConfigFileFinder::detectFromInput('rector', new ArgvInput());
|
|
|
|
$configFiles[] = ConfigFileFinder::provide('rector', ['rector.yml', 'rector.yaml']);
|
|
|
|
|
|
|
|
// remove empty values
|
|
|
|
$configFiles = array_filter($configFiles);
|
2018-06-13 10:33:45 +02:00
|
|
|
|
|
|
|
// 3. Build DI container
|
2019-02-23 00:08:58 +01:00
|
|
|
|
2019-02-23 00:19:33 +01:00
|
|
|
// to override the configs without clearing cache
|
|
|
|
$environment = 'prod' . random_int(1, 10000000);
|
|
|
|
$rectorKernel = new RectorKernel($environment, InputDetector::isDebug());
|
2018-08-30 11:33:52 +02:00
|
|
|
if ($configFiles) {
|
2019-02-23 00:08:58 +01:00
|
|
|
$rectorKernel->setConfigs($configFiles);
|
2018-06-13 10:33:45 +02:00
|
|
|
}
|
2019-02-23 00:08:58 +01:00
|
|
|
$rectorKernel->boot();
|
2018-06-13 10:33:45 +02:00
|
|
|
|
2019-02-23 00:08:58 +01:00
|
|
|
return $rectorKernel->getContainer();
|