3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \UrlRewrite \Controller ;
7
9
10
+ use Magento \Framework \App \Action \Forward ;
8
11
use Magento \Framework \App \Action \Redirect ;
12
+ use Magento \Framework \App \ActionFactory ;
9
13
use Magento \Framework \App \ActionInterface ;
10
14
use Magento \Framework \App \Request \Http as HttpRequest ;
11
15
use Magento \Framework \App \RequestInterface ;
12
16
use Magento \Framework \App \Response \Http as HttpResponse ;
17
+ use Magento \Framework \App \ResponseInterface ;
18
+ use Magento \Framework \App \RouterInterface ;
13
19
use Magento \Framework \Exception \NoSuchEntityException ;
14
20
use Magento \Framework \UrlInterface ;
21
+ use Magento \Store \Model \StoreManagerInterface ;
15
22
use Magento \UrlRewrite \Controller \Adminhtml \Url \Rewrite ;
16
23
use Magento \UrlRewrite \Model \UrlFinderInterface ;
17
24
use Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ;
21
28
*
22
29
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
23
30
*/
24
- class Router implements \ Magento \ Framework \ App \ RouterInterface
31
+ class Router implements RouterInterface
25
32
{
26
33
/**
27
- * @var \Magento\Framework\App\ ActionFactory
34
+ * @var ActionFactory
28
35
*/
29
36
protected $ actionFactory ;
30
37
@@ -34,7 +41,7 @@ class Router implements \Magento\Framework\App\RouterInterface
34
41
protected $ url ;
35
42
36
43
/**
37
- * @var \Magento\Store\Model\ StoreManagerInterface
44
+ * @var StoreManagerInterface
38
45
*/
39
46
protected $ storeManager ;
40
47
@@ -49,17 +56,17 @@ class Router implements \Magento\Framework\App\RouterInterface
49
56
protected $ urlFinder ;
50
57
51
58
/**
52
- * @param \Magento\Framework\App\ ActionFactory $actionFactory
59
+ * @param ActionFactory $actionFactory
53
60
* @param UrlInterface $url
54
- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
55
- * @param \Magento\Framework\App\ ResponseInterface $response
61
+ * @param StoreManagerInterface $storeManager
62
+ * @param ResponseInterface $response
56
63
* @param UrlFinderInterface $urlFinder
57
64
*/
58
65
public function __construct (
59
- \ Magento \ Framework \ App \ ActionFactory $ actionFactory ,
66
+ ActionFactory $ actionFactory ,
60
67
UrlInterface $ url ,
61
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
62
- \ Magento \ Framework \ App \ ResponseInterface $ response ,
68
+ StoreManagerInterface $ storeManager ,
69
+ ResponseInterface $ response ,
63
70
UrlFinderInterface $ urlFinder
64
71
) {
65
72
$ this ->actionFactory = $ actionFactory ;
@@ -83,24 +90,25 @@ public function match(RequestInterface $request)
83
90
$ this ->storeManager ->getStore ()->getId ()
84
91
);
85
92
86
- if ($ rewrite === null ) {
87
- //No rewrite rule matching current URl found, continuing with
88
- //processing of this URL.
93
+ if ($ rewrite === null || $ rewrite -> getRequestPath () === $ rewrite -> getTargetPath () ) {
94
+ // Either no rewrite rule matching current URl found or found one with request path equal to
95
+ // target path, continuing with processing of this URL.
89
96
return null ;
90
97
}
98
+
91
99
if ($ rewrite ->getRedirectType ()) {
92
- //Rule requires the request to be redirected to another URL
93
- //and cannot be processed further.
100
+ // Rule requires the request to be redirected to another URL
101
+ // and cannot be processed further.
94
102
return $ this ->processRedirect ($ request , $ rewrite );
95
103
}
96
- //Rule provides actual URL that can be processed by a controller.
104
+ // Rule provides actual URL that can be processed by a controller.
97
105
$ request ->setAlias (
98
106
UrlInterface::REWRITE_REQUEST_PATH_ALIAS ,
99
107
$ rewrite ->getRequestPath ()
100
108
);
101
109
$ request ->setPathInfo ('/ ' . $ rewrite ->getTargetPath ());
102
110
return $ this ->actionFactory ->create (
103
- \ Magento \ Framework \ App \ Action \ Forward::class
111
+ Forward::class
104
112
);
105
113
}
106
114
0 commit comments