1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Silverback\ApiComponentBundle\Command; |
6
|
|
|
|
7
|
|
|
use Silverback\ApiComponentBundle\ApiComponentBundleEvents; |
8
|
|
|
use Silverback\ApiComponentBundle\Event\CommandLogEvent; |
9
|
|
|
use Silverback\ApiComponentBundle\Form\Cache\FormCachePurger; |
10
|
|
|
use Symfony\Component\Console\Command\Command; |
11
|
|
|
use Symfony\Component\Console\Exception\InvalidArgumentException; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
15
|
|
|
|
16
|
|
|
class FormCachePurgeCommand extends Command |
17
|
|
|
{ |
18
|
|
|
private FormCachePurger $formCachePurger; |
19
|
|
|
private EventDispatcherInterface $dispatcher; |
20
|
|
|
|
21
|
|
|
public function __construct( |
22
|
|
|
FormCachePurger $formCachePurger, |
23
|
|
|
EventDispatcherInterface $dispatcher, |
24
|
|
|
?string $name = null |
25
|
|
|
) { |
26
|
|
|
$this->formCachePurger = $formCachePurger; |
27
|
|
|
$this->dispatcher = $dispatcher; |
28
|
|
|
parent::__construct($name); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @throws InvalidArgumentException |
33
|
|
|
*/ |
34
|
|
|
protected function configure(): void |
35
|
|
|
{ |
36
|
|
|
$this |
37
|
|
|
->setName('silverback:api-component:form-cache-purge') |
38
|
|
|
->setDescription('Purges the varnish cache for forms. Sets the `modified` timestamp to the file last modified date'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param InputInterface $input |
43
|
|
|
* @param OutputInterface $output |
44
|
|
|
* @return int|null|void |
45
|
|
|
*/ |
46
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
47
|
|
|
{ |
48
|
|
|
$this->dispatcher->addListener( |
49
|
|
|
ApiComponentBundleEvents::COMMAND_LOG, |
50
|
|
|
static function (CommandLogEvent $event) use ($output) { |
51
|
|
|
$output->writeln($event->getSubject()); |
52
|
|
|
} |
53
|
|
|
); |
54
|
|
|
$this->formCachePurger->clear(); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|