-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathClearCacheController.php
52 lines (41 loc) · 1.42 KB
/
ClearCacheController.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
48
49
50
51
52
<?php
declare(strict_types=1);
namespace Bolt\Controller\Backend;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Security("is_granted('clearcache')")
*/
class ClearCacheController extends AbstractController implements BackendZoneInterface
{
/**
* @Route("/clearcache", name="bolt_clear_cache")
*/
public function index(KernelInterface $kernel): Response
{
$output = $this->clearcache($kernel);
$this->addFlash('success', 'label.cache_cleared');
$twigvars = [
'output' => $output->fetch(),
];
return $this->render('@bolt/pages/clearcache.html.twig', $twigvars);
}
public function clearcache(KernelInterface $kernel): BufferedOutput
{
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new ArrayInput([
'command' => 'cache:clear',
'--no-warmup' => true,
]);
$output = new BufferedOutput();
$application->run($input, $output);
return $output;
}
}