From f1772afe156ebb0612d8031545160ed208c5fddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Fri, 7 Jul 2017 11:01:37 +0200 Subject: [PATCH] Allowing to set custom cache file --- src/Cache.php | 12 ++++++++++++ src/Command/LintCommand.php | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Cache.php b/src/Cache.php index 2fe21df5..5a15930b 100644 --- a/src/Cache.php +++ b/src/Cache.php @@ -57,12 +57,24 @@ public static function isCached() * Set cache. * * @param mixed $contents + * + * @return int */ public static function put($contents) { return file_put_contents(self::getFilename(), json_encode($contents)); } + /** + * Set cache filename. + * + * @param string $filename + */ + public static function setFilename($filename) + { + self::$filename = $filename; + } + /** * Return cache filename. * diff --git a/src/Command/LintCommand.php b/src/Command/LintCommand.php index 2b0d2850..43aa3cfa 100644 --- a/src/Command/LintCommand.php +++ b/src/Command/LintCommand.php @@ -94,6 +94,12 @@ protected function configure() null, InputOption::VALUE_NONE, 'Ignore cached data.' + ) + ->addOption( + 'cache', + null, + InputOption::VALUE_REQUIRED, + 'Path to the cache file.' ); } @@ -146,6 +152,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $linter = new Linter($options['path'], $options['exclude'], $options['extensions']); $linter->setProcessLimit($options['jobs']); + if ($input->getOption('cache') !== null) { + Cache::setFilename($input->getOption('cache')); + } + if (!$input->getOption('no-cache') && Cache::isCached()) { $output->writeln('Using cache.'); $linter->setCache(Cache::get());