Completed
Push — master ( 0be8e1...585ca2 )
by Daniel
59:26 queued 46:02
created

FormCacheClear::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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