Completed
Push — theme-bundle ( 2fd15f...927586 )
by Kamil
26:43 queued 10s
created

ThemeRepositoryPass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
c 1
b 1
f 0
lcom 0
cbo 3
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 19 3
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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
namespace Sylius\Bundle\ThemeBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\Config\Resource\FileResource;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
18
/**
19
 * @author Kamil Kokot <[email protected]>
20
 */
21
class ThemeRepositoryPass implements CompilerPassInterface
22
{
23
    /**
24
     * Adds serialized themes to theme repository.
25
     *
26
     * {@inheritdoc}
27
     */
28
    public function process(ContainerBuilder $container)
29
    {
30
        $definition = $container->findDefinition('sylius.theme.repository');
31
32
        $loader = $container->get('sylius.theme.loader');
33
34
        $serializedThemes = [];
35
        try {
36
            $themeFiles = $container->get('sylius.theme.locator')->locate('theme.json', null, false);
37
            foreach ($themeFiles as $themeFile) {
38
                $serializedThemes[] = serialize($loader->load($themeFile));
39
                $container->addResource(new FileResource($themeFile));
40
            }
41
42
            $definition->addArgument($serializedThemes);
43
        } catch (\InvalidArgumentException $e) {
44
            // No files found.
45
        }
46
    }
47
}
48