Completed
Push — master ( 4207f0...333332 )
by Kamil
23:19 queued 01:42
created

ThemeAwareLoader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A load() 0 18 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\Translation\Loader;
13
14
use Doctrine\Common\Collections\Collection;
15
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
16
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
17
use Symfony\Component\Translation\Loader\LoaderInterface;
18
19
/**
20
 * @author Kamil Kokot <[email protected]>
21
 */
22
final class ThemeAwareLoader implements LoaderInterface
23
{
24
    /**
25
     * @var LoaderInterface
26
     */
27
    private $loader;
28
29
    /**
30
     * @var ThemeRepositoryInterface
31
     */
32
    private $themeRepository;
33
34
    /**
35
     * @param LoaderInterface $loader
36
     * @param ThemeRepositoryInterface $themeRepository
37
     */
38
    public function __construct(LoaderInterface $loader, ThemeRepositoryInterface $themeRepository)
39
    {
40
        $this->loader = $loader;
41
        $this->themeRepository = $themeRepository;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function load($resource, $locale, $domain = 'messages')
48
    {
49
        $messageCatalogue = $this->loader->load($resource, $locale, $domain);
50
51
        $theme = $this->themeRepository->findOneByPath($resource);
52
        if (null !== $theme) {
53
            $messages = $messageCatalogue->all($domain);
54
55
            foreach ($messages as $key => $value) {
56
                unset($messages[$key]);
57
                $messages[$key . '|' . $theme->getSlug()] = $value;
58
            }
59
60
            $messageCatalogue->replace($messages, $domain);
61
        }
62
63
        return $messageCatalogue;
64
    }
65
}
66