getDashboardControllerFqcn()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\ThemeBundle\Helper;
15
16
use Symfony\Component\HttpFoundation\Request;
17
use Zikula\ThemeBundle\Controller\Dashboard\AdminDashboardController;
18
use Zikula\ThemeBundle\Controller\Dashboard\UserDashboardController;
19
20
/**
21
 * Helper for dynamic default dashboard selection, used by CreateThemedResponseSubscriber and non-EAB controllers.
22
 */
23
class FallbackDashboardDetector
24
{
25
    private const ROUTE_PART_ADMIN = '_admin_';
26
27
    public function isAdminArea(Request $request): bool
28
    {
29
        $route = $this->getRoute($request);
30
31
        return str_contains($route, self::ROUTE_PART_ADMIN);
32
    }
33
34
    public function getDashboardControllerFqcn(Request $request): string
35
    {
36
        $isAdminArea = $this->isAdminArea($request);
37
        $request->attributes->set('isAdminArea', $isAdminArea);
38
39
        return $isAdminArea ? AdminDashboardController::class : UserDashboardController::class;
40
    }
41
42
    private function getRoute(Request $request): string
43
    {
44
        return $request->attributes->get('_route') ?? '';
45
    }
46
}
47