Skip to content

Commit

Permalink
Merge pull request #23 from kubawerlos/allowing-to-set-custom-cache-file
Browse files Browse the repository at this point in the history
Allowing to set custom cache file
  • Loading branch information
overtrue authored Jul 7, 2017
2 parents aeb358e + f1772af commit c658052
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
10 changes: 10 additions & 0 deletions src/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
}

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit c658052

Please sign in to comment.