/
PurgeCachesWhenForced.php
47 lines (39 loc) · 1.18 KB
/
PurgeCachesWhenForced.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Application\Stage\Cache;
use phpDocumentor\Application\Stage\Payload;
use Psr\Log\LoggerInterface;
use Symfony\Component\Cache\Adapter\AdapterInterface;
final class PurgeCachesWhenForced
{
private $filesCache;
private $descriptorsCache;
private $logger;
public function __construct(
AdapterInterface $filesCache,
AdapterInterface $descriptorsCache,
LoggerInterface $logger
) {
$this->filesCache = $filesCache;
$this->descriptorsCache = $descriptorsCache;
$this->logger = $logger;
}
public function __invoke(Payload $payload)
{
$this->logger->info('Checking whether to purge cache');
if (!$payload->getConfig()['phpdocumentor']['use-cache']) {
$this->logger->info('Purging cache');
$this->filesCache->clear();
$this->descriptorsCache->clear();
}
return $payload;
}
}