Skip to content

Commit

Permalink
[TASK] Use rector-installer to load config of extensions
Browse files Browse the repository at this point in the history
- Relates: #6129
  • Loading branch information
sabbelasichon committed Apr 21, 2021
1 parent 4064d01 commit ca2fa6e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 39 deletions.
21 changes: 12 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@
"nette/robot-loader": "^3.4",
"nette/utils": "^3.2",
"nikic/php-parser": "^4.10.4",
"phpstan/phpstan": "^0.12.83",
"phpstan/phpdoc-parser": "^0.5.4",
"phpstan/phpstan": "^0.12.83",
"phpstan/phpstan-phpunit": "^0.12.18",
"rector/rector-symfony": "^0.10.3",
"rector/rector-nette": "^0.10.5",
"rector/rector-laravel": "^0.10.1",
"rector/rector-cakephp": "^0.10.3",
"rector/rector-phpunit": "^0.10.6",
"rector/rector-doctrine": "^0.10.2",
"rector/rector-cakephp": "dev-main",
"rector/rector-doctrine": "dev-main",
"rector/rector-installer": "dev-main",
"rector/rector-laravel": "dev-main",
"rector/rector-nette": "dev-main",
"rector/rector-phpunit": "dev-main",
"rector/rector-symfony": "dev-main",
"sebastian/diff": "^4.0.4",
"symfony/console": "^4.4.8|^5.1",
"symfony/dependency-injection": "^5.1",
Expand Down Expand Up @@ -73,7 +74,7 @@
"nette/forms": "^3.0",
"phpstan/phpstan-nette": "^0.12.16",
"phpunit/phpunit": "^9.5",
"rector/rector-generator": "^0.1.5",
"rector/rector-generator": "dev-main",
"symplify/coding-standard": "^9.2.16",
"symplify/easy-ci": "^9.2.16",
"symplify/easy-coding-standard": "^9.2.16",
Expand Down Expand Up @@ -153,5 +154,7 @@
"config": {
"sort-packages": true,
"platform-check": false
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
32 changes: 5 additions & 27 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

use Rector\Core\Bootstrap\ExtensionConfigResolver;
use Rector\Core\Configuration\Option;
use Rector\RectorGenerator\Bundle\RectorGeneratorBundle;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
Expand All @@ -12,32 +12,10 @@
$containerConfigurator->import(__DIR__ . '/services-packages.php');
$containerConfigurator->import(__DIR__ . '/parameters.php');

// rector root
$containerConfigurator->import(__DIR__ . '/../vendor/rector/rector-symfony/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../vendor/rector/rector-nette/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../vendor/rector/rector-laravel/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../vendor/rector/rector-phpunit/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../vendor/rector/rector-cakephp/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../vendor/rector/rector-doctrine/config/config.php', null, 'not_found');

// rector sub-package
$containerConfigurator->import(__DIR__ . '/../../rector-symfony/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../../rector-nette/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../../rector-laravel/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../../rector-phpunit/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../../rector-cakephp/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../../rector-doctrine/config/config.php', null, 'not_found');

// only for dev
// only for dev
if (class_exists(RectorGeneratorBundle::class)) {
$containerConfigurator->import(
__DIR__ . '/../vendor/rector/rector-generator/config/config.php',
null,
'not_found'
);
// 3rd party dependency
$containerConfigurator->import(__DIR__ . '/../../rector-generator/config/config.php', null, 'not_found');
$extensionConfigResolver = new ExtensionConfigResolver();
$extensionConfigFiles = $extensionConfigResolver->provide();
foreach ($extensionConfigFiles as $extensionConfigFile) {
$containerConfigurator->import($extensionConfigFile->getRealPath());
}

// require only in dev
Expand Down
5 changes: 3 additions & 2 deletions src/Bootstrap/ExtensionConfigResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
final class ExtensionConfigResolver
{
/**
* @param SmartFileInfo[] $configFileInfos
* @return SmartFileInfo[]
*/
public function appendExtensionsConfig(array $configFileInfos): array
public function provide(): array
{
$configFileInfos = [];

if (! class_exists('Rector\RectorInstaller\GeneratedConfig')) {
return $configFileInfos;
}
Expand Down
1 change: 0 additions & 1 deletion src/Bootstrap/RectorConfigsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public function provide(): BootstrapConfigs
) : [];

$configFileInfos = $this->appendRectorRecipeConfig($argvInput, $configFileInfos);
$configFileInfos = $this->extensionConfigResolver->appendExtensionsConfig($configFileInfos);

return new BootstrapConfigs($mainConfigFileInfo, $configFileInfos);
}
Expand Down

0 comments on commit ca2fa6e

Please sign in to comment.