1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Silverback API Components Bundle Project |
5
|
|
|
* |
6
|
|
|
* (c) Daniel West <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Silverback\ApiComponentsBundle\Command; |
15
|
|
|
|
16
|
|
|
use Silverback\ApiComponentsBundle\Event\CommandLogEvent; |
17
|
|
|
use Silverback\ApiComponentsBundle\Form\Cache\FormCachePurger; |
18
|
|
|
use Symfony\Component\Console\Command\Command; |
19
|
|
|
use Symfony\Component\Console\Exception\InvalidArgumentException; |
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
22
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Daniel West <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class FormCachePurgeCommand extends Command |
28
|
|
|
{ |
29
|
|
|
private FormCachePurger $formCachePurger; |
30
|
|
|
private EventDispatcherInterface $dispatcher; |
31
|
|
|
|
32
|
|
|
public function __construct( |
33
|
|
|
FormCachePurger $formCachePurger, |
34
|
|
|
EventDispatcherInterface $dispatcher, |
35
|
|
|
?string $name = null |
36
|
|
|
) { |
37
|
|
|
$this->formCachePurger = $formCachePurger; |
38
|
|
|
$this->dispatcher = $dispatcher; |
39
|
|
|
parent::__construct($name); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @throws InvalidArgumentException |
44
|
|
|
*/ |
45
|
|
|
protected function configure(): void |
46
|
|
|
{ |
47
|
|
|
$this |
48
|
|
|
->setName('silverback:api-components:form-cache-purge') |
49
|
|
|
->setDescription('Purges the varnish cache for forms. Sets the `modified` timestamp to the file last modified date'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return int|void|null |
54
|
|
|
*/ |
55
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
56
|
|
|
{ |
57
|
|
|
$this->dispatcher->addListener( |
58
|
|
|
CommandLogEvent::class, |
59
|
|
|
static function (CommandLogEvent $event) use ($output) { |
60
|
|
|
$output->writeln($event->getSubject()); |
61
|
|
|
} |
62
|
|
|
); |
63
|
|
|
$this->formCachePurger->clear(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|