From 66b5923ad7245f638e8fb6beef85202e1d4f7de2 Mon Sep 17 00:00:00 2001 From: Wouter Rutgers <git@wouterrutgers.nl> Date: Thu, 8 Sep 2022 15:58:18 +0200 Subject: [PATCH] add configuration option to overwrite cache file location (#111) * add configuration option to overwrite cache file location * remove .idea exclusion from gitignore * Update ConfigurationResolverFactory.php * Update ConfigurationJsonRepository.php Co-authored-by: Taylor Otwell <taylor@laravel.com> --- .../ConfigurationResolverFactory.php | 6 ++++-- .../ConfigurationJsonRepository.php | 20 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/Factories/ConfigurationResolverFactory.php b/app/Factories/ConfigurationResolverFactory.php index cc26e50c..03fbd871 100644 --- a/app/Factories/ConfigurationResolverFactory.php +++ b/app/Factories/ConfigurationResolverFactory.php @@ -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.'); @@ -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() diff --git a/app/Repositories/ConfigurationJsonRepository.php b/app/Repositories/ConfigurationJsonRepository.php index 5d1c7770..7b3e0515 100644 --- a/app/Repositories/ConfigurationJsonRepository.php +++ b/app/Repositories/ConfigurationJsonRepository.php @@ -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 @@ -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> */ @@ -40,7 +40,7 @@ public function finder() } /** - * Gets the rules options. + * Get the rules options. * * @return array<int, string> */ @@ -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 */ @@ -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> */