1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Silverback\ApiComponentBundle\Command; |
6
|
|
|
|
7
|
|
|
use Silverback\ApiComponentBundle\Cache\FormCacheClearer; |
8
|
|
|
use Silverback\ApiComponentBundle\Event\CommandNotifyEvent; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
13
|
|
|
|
14
|
|
|
class FormCacheClear extends Command |
15
|
|
|
{ |
16
|
|
|
private $cacheClearer; |
17
|
|
|
private $dispatcher; |
18
|
|
|
|
19
|
|
|
public function __construct( |
20
|
|
|
FormCacheClearer $cacheClearer, |
21
|
|
|
EventDispatcherInterface $dispatcher, |
22
|
|
|
?string $name = null |
23
|
|
|
) { |
24
|
|
|
$this->cacheClearer = $cacheClearer; |
25
|
|
|
$this->dispatcher = $dispatcher; |
26
|
|
|
parent::__construct($name); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
31
|
|
|
*/ |
32
|
|
|
protected function configure(): void |
33
|
|
|
{ |
34
|
|
|
$this |
35
|
|
|
->setName('silverback:api_component:clear_form_cache') |
36
|
|
|
->setDescription('Purges the varnish cache for forms where files have been updated'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param InputInterface $input |
41
|
|
|
* @param OutputInterface $output |
42
|
|
|
* @return int|null|void |
43
|
|
|
*/ |
44
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
45
|
|
|
{ |
46
|
|
|
$this->dispatcher->addListener( |
47
|
|
|
FormCacheClearer::FORM_CACHE_EVENT_NAME, |
48
|
|
|
function (CommandNotifyEvent $event) use ($output) { |
49
|
|
|
$output->writeln($event->getSubject()); |
50
|
|
|
} |
51
|
|
|
); |
52
|
|
|
$this->cacheClearer->clear(); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|