-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCustomRouter.php
83 lines (74 loc) · 2.05 KB
/
CustomRouter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* @author Artemii Karkusha
* @copyright Copyright (c) (https://www.linkedin.com/in/artemiy-karkusha/)
*/
declare(strict_types=1);
namespace ArtemiiKarkusha\AdobeCommercePreparingToCertification\Controller;
use Magento\Framework\App\Action\Forward as ActionForward;
use Magento\Framework\App\ActionFactory;
use Magento\Framework\App\ActionInterface;
use Magento\Framework\App\Request\Http as RequestHttp;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\RouterInterface;
class CustomRouter implements RouterInterface
{
/**
* @param ActionFactory $actionFactory
*/
public function __construct(
private ActionFactory $actionFactory
) {
}
/**
* Validate and Match Cms Page and modify request
*
* @param RequestInterface $request
* @return ActionInterface
* @noinspection PhpParamsInspection
*/
public function match(RequestInterface $request): ActionInterface
{
if (
$this->canBeProcessed($request) &&
$this->isRequestContainsMatchedIdentifier($request)
) {
$this->setUpRequest($request);
}
return $this->actionFactory->create(ActionForward::class);
}
/**
*
* @param RequestInterface $request
* @return bool
*/
private function canBeProcessed(RequestInterface $request): bool
{
return $request instanceof RequestHttp;
}
/**
*
* @param RequestHttp $request
* @return bool
*/
private function isRequestContainsMatchedIdentifier(RequestHttp $request): bool
{
$identifier = trim($request->getPathInfo(), '/');
return str_contains($identifier, 'customrouter');
}
/**
*
* @param RequestHttp $request
* @return void
*/
private function setUpRequest(RequestHttp $request): void
{
$request->setModuleName('customrouter')
->setControllerName('page')
->setActionName('index')
->setParam(
'param',
3
);
}
}