1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||
6 | */ |
||
7 | |||
8 | namespace Spryker\Glue\Kernel\Plugin\EventDispatcher; |
||
9 | |||
10 | use Spryker\Glue\Kernel\AbstractPlugin; |
||
11 | use Spryker\Service\Container\ContainerInterface; |
||
12 | use Spryker\Shared\EventDispatcher\EventDispatcherInterface; |
||
13 | use Spryker\Shared\EventDispatcherExtension\Dependency\Plugin\EventDispatcherPluginInterface; |
||
14 | use Spryker\Shared\Kernel\ClassResolver\ResolverCacheManager; |
||
15 | use Symfony\Component\HttpKernel\KernelEvents; |
||
16 | |||
17 | class AutoloaderCacheEventDispatcherPlugin extends AbstractPlugin implements EventDispatcherPluginInterface |
||
18 | { |
||
19 | /** |
||
20 | * {@inheritDoc} |
||
21 | * - Adds a listener for the `\Symfony\Component\HttpKernel\KernelEvents::TERMINATE` event, which will write a class resolver cache. |
||
22 | * |
||
23 | * @api |
||
24 | * |
||
25 | * @param \Spryker\Shared\EventDispatcher\EventDispatcherInterface $eventDispatcher |
||
26 | * @param \Spryker\Service\Container\ContainerInterface $container |
||
27 | * |
||
28 | * @return \Spryker\Shared\EventDispatcher\EventDispatcherInterface |
||
29 | */ |
||
30 | public function extend(EventDispatcherInterface $eventDispatcher, ContainerInterface $container): EventDispatcherInterface |
||
31 | { |
||
32 | $eventDispatcher->addListener(KernelEvents::TERMINATE, function () { |
||
33 | $this->persistClassResolverCache(); |
||
34 | }); |
||
35 | |||
36 | return $eventDispatcher; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @return void |
||
41 | */ |
||
42 | protected function persistClassResolverCache(): void |
||
43 | { |
||
44 | $resolverCacheManager = new ResolverCacheManager(); |
||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||
45 | |||
46 | if (!$resolverCacheManager->useCache()) { |
||
47 | return; |
||
48 | } |
||
49 | |||
50 | $cacheProvider = $resolverCacheManager->createClassResolverCacheProvider(); |
||
51 | $cacheProvider->getCache()->persist(); |
||
52 | } |
||
53 | } |
||
54 |