Skip to content

Commit

Permalink
[internal] Add RelatedConfigInterface to load external services (#5605)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 12, 2024
1 parent 8d524d4 commit 62ba916
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Config/RectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Configuration\RectorConfigBuilder;
use Rector\Contract\DependencyInjection\RelatedConfigInterface;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Contract\Rector\RectorInterface;
use Rector\DependencyInjection\Laravel\ContainerMemento;
Expand Down Expand Up @@ -251,6 +252,19 @@ public function rules(array $rectorClasses): void

foreach ($rectorClasses as $rectorClass) {
$this->rule($rectorClass);

if (is_a($rectorClass, RelatedConfigInterface::class, true)) {
/** @var RelatedConfigInterface $rector */
$rector = $this->make($rectorClass);

Assert::file($rector->getConfigFile(), sprintf(
'The config path "%s" in "%s::getConfigFile()" could not be found',
$rector->getConfigFile(),
$rector::class
));

$this->import($rector->getConfigFile());
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/Contract/DependencyInjection/RelatedConfigInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Rector\Contract\DependencyInjection;

/**
* @internal Use for rules that require extra custom services.
*/
interface RelatedConfigInterface
{
public function getConfigFile(): string;
}

0 comments on commit 62ba916

Please sign in to comment.