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

systemsdk / docker-symfony-api / #74

pending completion
#74

push

DKravtsov
Php 8.2, symfony 6.2, updated RabbitMQ, updated composer dependencies, refactoring.

51 of 51 new or added lines in 44 files covered. (100.0%)

1479 of 2668 relevant lines covered (55.43%)

23.59 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
    }
145✔
36

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

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

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

66
        $request->setLocale($locale);
145✔
67
    }
68
}
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