|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace IntegerNet\AsyncVarnish\Observer; |
|
5
|
|
|
|
|
6
|
|
|
use Magento\Framework\Event\ObserverInterface; |
|
7
|
|
|
|
|
8
|
|
|
class InvalidateVarnishAsyncObserver implements ObserverInterface |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Application config object |
|
12
|
|
|
* |
|
13
|
|
|
* @var \Magento\Framework\App\Config\ScopeConfigInterface |
|
14
|
|
|
*/ |
|
15
|
|
|
private $config; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var \Magento\CacheInvalidate\Model\PurgeCache |
|
19
|
|
|
*/ |
|
20
|
|
|
private $purgeCache; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Invalidation tags resolver |
|
24
|
|
|
* |
|
25
|
|
|
* @var \Magento\Framework\App\Cache\Tag\Resolver |
|
26
|
|
|
*/ |
|
27
|
|
|
private $tagResolver; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Async tags storage |
|
31
|
|
|
* |
|
32
|
|
|
* @var \IntegerNet\AsyncVarnish\Model\TagRepository |
|
33
|
|
|
*/ |
|
34
|
|
|
private $tagRepository; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param \Magento\PageCache\Model\Config $config |
|
38
|
|
|
* @param \Magento\CacheInvalidate\Model\PurgeCache $purgeCache |
|
39
|
|
|
* @param \Magento\Framework\App\Cache\Tag\Resolver $tagResolver |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct( |
|
42
|
|
|
\Magento\PageCache\Model\Config $config, |
|
43
|
|
|
\Magento\CacheInvalidate\Model\PurgeCache $purgeCache, |
|
44
|
|
|
\Magento\Framework\App\Cache\Tag\Resolver $tagResolver, |
|
45
|
|
|
\IntegerNet\AsyncVarnish\Model\TagRepository $tagRepository |
|
46
|
|
|
) { |
|
47
|
|
|
$this->config = $config; |
|
|
|
|
|
|
48
|
|
|
$this->purgeCache = $purgeCache; |
|
49
|
|
|
$this->tagResolver = $tagResolver; |
|
50
|
|
|
$this->tagRepository = $tagRepository; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* If Varnish caching is enabled it collects array of tags |
|
55
|
|
|
* of incoming object and asks to clean cache. |
|
56
|
|
|
* |
|
57
|
|
|
* @param \Magento\Framework\Event\Observer $observer |
|
58
|
|
|
* @return void |
|
59
|
|
|
* @throws \Exception |
|
60
|
|
|
*/ |
|
61
|
|
|
public function execute(\Magento\Framework\Event\Observer $observer) |
|
62
|
|
|
{ |
|
63
|
|
|
$object = $observer->getEvent()->getObject(); |
|
64
|
|
|
if (!is_object($object)) { |
|
65
|
|
|
return; |
|
66
|
|
|
} |
|
67
|
|
|
if ($this->config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->config->isEnabled()) { |
|
|
|
|
|
|
68
|
|
|
$bareTags = $this->tagResolver->getTags($object); |
|
69
|
|
|
|
|
70
|
|
|
$tags = []; |
|
71
|
|
|
$pattern = "((^|,)%s(,|$))"; |
|
72
|
|
|
foreach ($bareTags as $tag) { |
|
73
|
|
|
$tags[] = sprintf($pattern, $tag); |
|
74
|
|
|
} |
|
75
|
|
|
if (!empty($tags)) { |
|
76
|
|
|
$this->tagRepository->insertMultiple($tags); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..