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

ThemeAwareLoader::load()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 18
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 10
nc 2
nop 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