Skip to content

Commit

Permalink
[Container] Add RectorConfig::containerCacheDirectory() (#3490)
Browse files Browse the repository at this point in the history
* [Container] Add RectorConfig::containerCacheDirectory()

* final touch: future comment

* final touch: clean up

* final touch: clean up

* final touch: clean up

* final touch: clean up

* final touch: clean up
  • Loading branch information
samsonasik authored Mar 19, 2023
1 parent 13a25fe commit 5371408
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
$rectorConfig->nestedChainMethodCallLimit(120);

$rectorConfig->cacheDirectory(sys_get_temp_dir() . '/rector_cached_files');
$rectorConfig->containerCacheDirectory(sys_get_temp_dir());

$services = $rectorConfig->services();
$services->defaults()
Expand Down
11 changes: 11 additions & 0 deletions packages/Config/RectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,21 @@ public function nestedChainMethodCallLimit(int $limit): void

public function cacheDirectory(string $directoryPath): void
{
// cache directory path is created via mkdir in CacheFactory
// when not exists, so no need to validate $directoryPath is a directory
$parameters = $this->parameters();
$parameters->set(Option::CACHE_DIR, $directoryPath);
}

public function containerCacheDirectory(string $directoryPath): void
{
// container cache directory path must be a directory on the first place
Assert::directory($directoryPath);

$parameters = $this->parameters();
$parameters->set(Option::CONTAINER_CACHE_DIRECTORY, $directoryPath);
}

/**
* @param class-string<CacheStorageInterface> $cacheClass
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ public function __construct(
}

$containerFactory = new ContainerFactory(getcwd());
$this->container = $containerFactory->create(sys_get_temp_dir(), $additionalConfigFiles, []);
$this->container = $containerFactory->create(
$parameterProvider->provideStringParameter(Option::CONTAINER_CACHE_DIRECTORY),
$additionalConfigFiles,
[]
);

// clear temporary files, after container is created
$filesystem = new Filesystem();
Expand Down
6 changes: 6 additions & 0 deletions src/Configuration/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,10 @@ final class Option
* @var string
*/
public const REMOVE_UNUSED_IMPORTS = 'remove-unused-imports';

/**
* @internal Use @see \Rector\Config\RectorConfig::containerCacheDirectory() method
* @var string
*/
public const CONTAINER_CACHE_DIRECTORY = 'container-cache-directory';
}

0 comments on commit 5371408

Please sign in to comment.