Skip to content

Commit

Permalink
[DI] Add resetable interface to reset services on new DI run (#4790)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Aug 14, 2023
1 parent 98b203a commit 2fe68ad
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
use PHPStan\Reflection\BetterReflection\SourceLocator\FileNodesFetcher;
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocator;
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocator;
use Rector\Core\Contract\DependencyInjection\ResetableInterface;
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
use Webmozart\Assert\Assert;

/**
* @api phpstan external
*/
final class DynamicSourceLocatorProvider
final class DynamicSourceLocatorProvider implements ResetableInterface
{
/**
* @var string[]
Expand Down
8 changes: 7 additions & 1 deletion src/Configuration/RenamedClassesDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Rector\Core\Configuration;

use PHPStan\Type\ObjectType;
use Rector\Core\Contract\DependencyInjection\ResetableInterface;

final class RenamedClassesDataCollector
final class RenamedClassesDataCollector implements ResetableInterface
{
/**
* @var array<string, string>
Expand Down Expand Up @@ -55,4 +56,9 @@ public function getOldClasses(): array
{
return array_keys($this->oldToNewClasses);
}

public function reset(): void
{
$this->oldToNewClasses = [];
}
}
10 changes: 10 additions & 0 deletions src/Contract/DependencyInjection/ResetableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Contract\DependencyInjection;

interface ResetableInterface
{
public function reset(): void;
}
6 changes: 6 additions & 0 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use Rector\Core\Application\FileProcessor\PhpFileProcessor;
use Rector\Core\Configuration\ConfigInitializer;
use Rector\Core\Configuration\CurrentNodeProvider;
use Rector\Core\Configuration\RenamedClassesDataCollector;
use Rector\Core\Console\Command\ListRulesCommand;
use Rector\Core\Console\Command\ProcessCommand;
use Rector\Core\Console\Command\SetupCICommand;
Expand All @@ -56,6 +57,7 @@
use Rector\Core\Console\Output\OutputFormatterCollector;
use Rector\Core\Console\Style\RectorStyle;
use Rector\Core\Console\Style\SymfonyStyleFactory;
use Rector\Core\Contract\DependencyInjection\ResetableInterface;
use Rector\Core\Contract\Processor\FileProcessorInterface;
use Rector\Core\Contract\Rector\PhpRectorInterface;
use Rector\Core\Contract\Rector\RectorInterface;
Expand Down Expand Up @@ -465,6 +467,10 @@ static function (Container $container): DynamicSourceLocatorProvider {
}
);

// resetables
$lazyRectorConfig->tag(DynamicSourceLocatorProvider::class, ResetableInterface::class);
$lazyRectorConfig->tag(RenamedClassesDataCollector::class, ResetableInterface::class);

// caching
$lazyRectorConfig->singleton(Cache::class, static function (Container $container): Cache {
/** @var CacheFactory $cacheFactory */
Expand Down

0 comments on commit 2fe68ad

Please sign in to comment.