Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Container] Add RectorConfig::containerCacheDirectory() #3490

Merged
merged 7 commits into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(60);

$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';
}