• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemsdk / docker-symfony-api / #83

pending completion
#83

push

DKravtsov
Updated composer dependencies, refactoring.

45 of 45 new or added lines in 12 files covered. (100.0%)

1483 of 2844 relevant lines covered (52.14%)

22.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/src/Tool/Transport/EventSubscriber/AcceptLanguageSubscriber.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Tool\Transport\EventSubscriber;
6

7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
use Symfony\Component\HttpKernel\Event\RequestEvent;
9

10
use function in_array;
11

12
/**
13
 * Class AcceptLanguageSubscriber
14
 *
15
 * @package App\Tool
16
 */
17
class AcceptLanguageSubscriber implements EventSubscriberInterface
18
{
19
    // Supported locales
20
    public const LOCALE_EN = 'en';
21
    public const LOCALE_RU = 'ru';
22
    public const LOCALE_UA = 'ua';
23
    public const LOCALE_FI = 'fi';
24

25
    public const SUPPORTED_LOCALES = [
26
        self::LOCALE_EN,
27
        self::LOCALE_RU,
28
        self::LOCALE_UA,
29
        self::LOCALE_FI,
30
    ];
31

32
    public function __construct(
33
        private readonly string $locale,
34
    ) {
35
    }
148✔
36

37
    /**
38
     * {@inheritdoc}
39
     */
40
    public static function getSubscribedEvents(): array
41
    {
42
        return [
×
43
            RequestEvent::class => [
×
44
                'onKernelRequest',
×
45
                // Note that this needs to at least `100` to get translation messages as expected
46
                100,
×
47
            ],
×
48
        ];
×
49
    }
50

51
    /**
52
     * Method to change used locale according to current request.
53
     */
54
    public function onKernelRequest(RequestEvent $event): void
55
    {
56
        $request = $event->getRequest();
148✔
57
        $locale = $request->headers->get('Accept-Language', $this->locale);
148✔
58

59
        // Ensure that given locale is supported, if not fallback to default.
60
        if (!in_array($locale, self::SUPPORTED_LOCALES, true)) {
148✔
61
            $locale = $this->locale;
148✔
62
        }
63

64
        $request->setLocale($locale);
148✔
65
    }
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc