Passed
Push — main ( 3affe5...43c7bb )
by Axel
04:16
created

ZikulaThemeExtension::prepareThemeConfig()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
nc 4
nop 1
dl 0
loc 14
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
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 Zikula\ThemeBundle\DependencyInjection;
15
16
use Symfony\Component\Config\FileLocator;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
19
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
20
use Zikula\ThemeBundle\Controller\Dashboard\AdminDashboardController;
21
use Zikula\ThemeBundle\Controller\Dashboard\UserDashboardController;
22
use Zikula\ThemeBundle\EventListener\OutputCompressionListener;
23
24
class ZikulaThemeExtension extends Extension
25
{
26
    public function load(array $configs, ContainerBuilder $container)
27
    {
28
        $loader = new YamlFileLoader($container, new FileLocator(dirname(__DIR__) . '/Resources/config'));
29
        $loader->load('services.yaml');
30
31
        $configuration = new Configuration();
32
        $config = $this->processConfiguration($configuration, $configs);
33
34
        $container->setParameter('zikula_theme_user_dashboard', $config['user_dashboard']['class']);
35
        $container->setParameter('zikula_theme_admin_dashboard', $config['admin_dashboard']['class']);
36
37
        $container->getDefinition(AdminDashboardController::class)
38
            ->setArgument('$themeConfig', $this->prepareThemeConfig($config['admin_dashboard']));
39
40
        $container->getDefinition(UserDashboardController::class)
41
            ->setArgument('$themeConfig', $this->prepareThemeConfig($config['user_dashboard']));
42
43
        $container->getDefinition(OutputCompressionListener::class)
44
            ->setArgument('$useCompression', $config['use_compression']);
45
    }
46
47
    private function prepareThemeConfig(array $themeConfig): array
48
    {
49
        if (null === $themeConfig['content']['redirect']['route']) {
50
            return $themeConfig;
51
        }
52
        if (empty($themeConfig['content']['redirect']['route_parameters'])) {
53
            return $themeConfig;
54
        }
55
56
        foreach ($themeConfig['content']['redirect']['route_parameters'] as $key => $entry) {
57
            $themeConfig['content']['redirect']['route_parameters'][$key] = $entry['value'];
58
        }
59
60
        return $themeConfig;
61
    }
62
}
63