TranslatorMiddlewareFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * This File is Part of the Validus Translation package.
4
 *
5
 * @copyright (c) 2018 Validus <https://github.com/ValidusPHP/>
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
declare(strict_types=1);
12
13
namespace Validus\Translation\Middleware;
14
15
use Psr\Container\ContainerInterface;
16
use Symfony\Component\Translation\Translator;
17
18
class TranslatorMiddlewareFactory
19
{
20
    public function __invoke(ContainerInterface $container): TranslatorMiddleware
21
    {
22
        /** @var Translator $translator */
23
        $translator = $container->get(Translator::class);
24
        $config = $container->has('config') ? $container->get('config') : [];
25
26
        $config = $config['translator'] ?? [];
27
28
        $priorities = $config['priorities'] ?? $config['fallback'] ?? [$translator->getLocale()];
29
30
        return new TranslatorMiddleware($translator, $priorities);
31
    }
32
}
33