Completed
Push — master ( 52b242...112fdc )
by Thomas
17s queued 11s
created

WatchContainerDefinitionsAction::getOptionsClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the ekino Drupal Debug project.
7
 *
8
 * (c) ekino
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ekino\Drupal\Debug\Action\WatchContainerDefinitions;
15
16
use Ekino\Drupal\Debug\Action\ActionWithOptionsInterface;
17
use Ekino\Drupal\Debug\Action\EventSubscriberActionInterface;
18
use Ekino\Drupal\Debug\Cache\FileBackend;
19
use Ekino\Drupal\Debug\Cache\FileCache;
20
use Ekino\Drupal\Debug\Helper\SettingsHelper;
21
use Ekino\Drupal\Debug\Kernel\Event\AfterSettingsInitializationEvent;
22
use Ekino\Drupal\Debug\Kernel\Event\DebugKernelEvents;
23
24
class WatchContainerDefinitionsAction implements EventSubscriberActionInterface, ActionWithOptionsInterface
25
{
26
    /**
27
     * @var WatchContainerDefinitionsOptions
28
     */
29
    private $options;
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 1
    public static function getSubscribedEvents(): array
35
    {
36
        return array(
37 1
            DebugKernelEvents::AFTER_SETTINGS_INITIALIZATION => 'process',
38
        );
39
    }
40
41
    /**
42
     * @param WatchContainerDefinitionsOptions $options
43
     */
44 3
    public function __construct(WatchContainerDefinitionsOptions $options)
45
    {
46 3
        $this->options = $options;
47 3
    }
48
49 1
    public function process(AfterSettingsInitializationEvent $event): void
50
    {
51 1
        (new SettingsHelper())->override('[bootstrap_container_definition]', array(
52
            'services' => array(
53
                'cache.container' => array(
54 1
                    'class' => FileBackend::class,
55
                    'arguments' => array(
56 1
                        $fileCache = new FileCache($this->options->getCacheFilePath(), $this->options->getFilteredResourcesCollection($event->getEnabledModules(), $event->getEnabledThemes())),
57
                    ),
58
                ),
59
            ),
60
        ));
61
62 1
        if ($event->doesConfigurationChanged()) {
63
            $fileCache->invalidate();
64
        }
65 1
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 1
    public static function getOptionsClass(): string
71
    {
72 1
        return WatchContainerDefinitionsOptions::class;
73
    }
74
}
75