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