Completed
Push — master ( f3cf07...ead026 )
by Paweł
237:27 queued 221:30
created

CompositeLocaleContext::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the Sylius package.
4
 *
5
 * (c) Paweł Jędrzejewski
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Sylius\Component\Locale\Context;
12
13
use Zend\Stdlib\PriorityQueue;
14
15
/**
16
 * @author Kamil Kokot <[email protected]>
17
 */
18
final class CompositeLocaleContext implements LocaleContextInterface
19
{
20
    /**
21
     * @var PriorityQueue|LocaleContextInterface[]
22
     */
23
    private $localeContexts;
24
25
    public function __construct()
26
    {
27
        $this->localeContexts = new PriorityQueue();
28
    }
29
30
    /**
31
     * @param LocaleContextInterface $localeContext
32
     * @param int $priority
33
     */
34
    public function addContext(LocaleContextInterface $localeContext, $priority = 0)
35
    {
36
        $this->localeContexts->insert($localeContext, $priority);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getLocaleCode()
43
    {
44
        foreach ($this->localeContexts as $localeContext) {
45
            try {
46
                return $localeContext->getLocaleCode();
47
            } catch (LocaleNotFoundException $exception) {
48
                continue;
49
            }
50
        }
51
52
        throw new LocaleNotFoundException();
53
    }
54
}
55