Skip to content

Commit

Permalink
add configuration option to overwrite cache file location (#111)
Browse files Browse the repository at this point in the history
* add configuration option to overwrite cache file location

* remove .idea exclusion from gitignore

* Update ConfigurationResolverFactory.php

* Update ConfigurationJsonRepository.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
wouterrutgers and taylorotwell authored Sep 8, 2022
1 parent 36ba11b commit 66b5923
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
6 changes: 4 additions & 2 deletions app/Factories/ConfigurationResolverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public static function fromIO($input, $output)
{
$path = $input->getArgument('path');

$preset = resolve(ConfigurationJsonRepository::class)->preset();
$localConfiguration = resolve(ConfigurationJsonRepository::class);

$preset = $localConfiguration->preset();

if (! in_array($preset, static::$presets)) {
abort(1, 'Preset not found.');
Expand All @@ -54,7 +56,7 @@ public static function fromIO($input, $output)
'dry-run' => $input->getOption('test'),
'path' => $path,
'path-mode' => ConfigurationResolver::PATH_MODE_OVERRIDE,
'cache-file' => implode(DIRECTORY_SEPARATOR, [
'cache-file' => $localConfiguration->cacheFile() ?? implode(DIRECTORY_SEPARATOR, [
realpath(sys_get_temp_dir()),
md5(
app()->isProduction()
Expand Down
20 changes: 15 additions & 5 deletions app/Repositories/ConfigurationJsonRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ConfigurationJsonRepository
];

/**
* Creates a new Configuration Json Repository instance.
* Create a new Configuration Json Repository instance.
*
* @param string|null $path
* @param string|null $preset
Expand All @@ -28,7 +28,7 @@ public function __construct(protected $path, protected $preset)
}

/**
* Gets the finder options.
* Get the finder options.
*
* @return array<string, array<int, string>|string>
*/
Expand All @@ -40,7 +40,7 @@ public function finder()
}

/**
* Gets the rules options.
* Get the rules options.
*
* @return array<int, string>
*/
Expand All @@ -50,7 +50,17 @@ public function rules()
}

/**
* Gets the preset option.
* Get the cache file location.
*
* @return string|null
*/
public function cacheFile()
{
return $this->get()['cache-file'] ?? null;
}

/**
* Get the preset option.
*
* @return string
*/
Expand All @@ -60,7 +70,7 @@ public function preset()
}

/**
* Gets the configuration from the "pint.json" file.
* Get the configuration from the "pint.json" file.
*
* @return array<string, array<int, string>|string>
*/
Expand Down

0 comments on commit 66b5923

Please sign in to comment.