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\Helper\Form\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(FormCachePurger $formCachePurger, EventDispatcherInterface $dispatcher, ?string $name = null) |
33
|
|
|
{ |
34
|
|
|
$this->formCachePurger = $formCachePurger; |
35
|
|
|
$this->dispatcher = $dispatcher; |
36
|
|
|
parent::__construct($name); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @throws InvalidArgumentException |
41
|
|
|
*/ |
42
|
|
|
protected function configure(): void |
43
|
|
|
{ |
44
|
|
|
$this |
45
|
|
|
->setName('silverback:api-components:form-cache-purge') |
46
|
|
|
->setDescription('Purges the varnish cache for forms. Sets the `modified` timestamp to the file last modified date'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return int|void|null |
51
|
|
|
*/ |
52
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
53
|
|
|
{ |
54
|
|
|
$this->dispatcher->addListener( |
55
|
|
|
CommandLogEvent::class, |
56
|
|
|
static function (CommandLogEvent $event) use ($output) { |
57
|
|
|
$output->writeln($event->getSubject()); |
58
|
|
|
} |
59
|
|
|
); |
60
|
|
|
$this->formCachePurger->clear(); |
61
|
|
|
$output->writeln('Form cache purge complete'); |
62
|
|
|
|
63
|
|
|
return 0; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|