1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula Foundation - 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\Bundle\CoreBundle\Controller; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
18
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface; |
19
|
|
|
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface; |
20
|
|
|
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Main controller. |
24
|
|
|
*/ |
25
|
|
|
class MainController |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var ZikulaHttpKernelInterface |
29
|
|
|
*/ |
30
|
|
|
private $kernel; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var VariableApiInterface |
34
|
|
|
*/ |
35
|
|
|
private $variableApi; |
36
|
|
|
|
37
|
|
|
public function __construct( |
38
|
|
|
ZikulaHttpKernelInterface $kernel, |
39
|
|
|
VariableApiInterface $variableApi |
40
|
|
|
) { |
41
|
|
|
$this->kernel = $kernel; |
42
|
|
|
$this->variableApi = $variableApi; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* This controller action is designed for the "/" route (home). |
47
|
|
|
* The route definition is set in `CoreBundle/Resources/config/routing.xml` |
48
|
|
|
*/ |
49
|
|
|
public function homeAction(Request $request): Response |
50
|
|
|
{ |
51
|
|
|
$startPageInfo = $this->variableApi->getSystemVar('startController'); |
52
|
|
|
if (!is_array($startPageInfo) || !isset($startPageInfo['controller']) || empty($startPageInfo['controller'])) { |
53
|
|
|
return new Response(''); // home page is static |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$isValidStartController = true; |
57
|
|
|
[$route, $controller] = explode('###', $startPageInfo['controller']); |
58
|
|
|
if (false === mb_strpos($controller, '\\') || false === mb_strpos($controller, '::')) { |
59
|
|
|
$isValidStartController = false; |
60
|
|
|
} else { |
61
|
|
|
[$vendor, $extensionName] = explode('\\', $controller); |
62
|
|
|
$extensionName = $vendor . $extensionName; |
63
|
|
|
[$fqcn, $method] = explode('::', $controller); |
64
|
|
|
if (!$this->kernel->isBundle($extensionName) || !class_exists($fqcn) || !is_callable([$fqcn, $method])) { |
65
|
|
|
$isValidStartController = false; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (!$isValidStartController) { |
70
|
|
|
return new Response(''); // home page is static |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$queryParams = $requestParams = $attributes = []; |
74
|
|
|
if (null !== $startPageInfo['query']) { |
75
|
|
|
parse_str($startPageInfo['query'], $queryParams); |
76
|
|
|
} |
77
|
|
|
if (null !== $startPageInfo['request']) { |
78
|
|
|
parse_str($startPageInfo['request'], $requestParams); |
79
|
|
|
} |
80
|
|
|
if (null !== $startPageInfo['attributes']) { |
81
|
|
|
parse_str($startPageInfo['attributes'], $attributes); |
82
|
|
|
} |
83
|
|
|
$attributes['_controller'] = $controller; |
84
|
|
|
$attributes['_route'] = $route; |
85
|
|
|
|
86
|
|
|
$subRequest = $request->duplicate($queryParams, $requestParams, $attributes); |
87
|
|
|
|
88
|
|
|
$subRequest->attributes->set('_zkBundle', $extensionName); |
|
|
|
|
89
|
|
|
$subRequest->attributes->set('_zkModule', $extensionName); |
90
|
|
|
// fix for #3929, #3932 |
91
|
|
|
$request->attributes->set('_zkBundle', $extensionName); |
92
|
|
|
$request->attributes->set('_zkModule', $extensionName); |
93
|
|
|
|
94
|
|
|
return $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|