1
1
<?php
2
+
3
+ declare (strict_types=1 );
4
+
2
5
/**
3
6
* Copyright © Magento, Inc. All rights reserved.
4
7
* See COPYING.txt for license details.
5
8
*/
6
9
namespace Magento \Review \Controller ;
7
10
11
+ use Magento \Catalog \Api \CategoryRepositoryInterface ;
12
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
13
+ use Magento \Catalog \Model \Design ;
8
14
use Magento \Catalog \Model \Product as CatalogProduct ;
15
+ use Magento \Customer \Model \Session ;
16
+ use Magento \Customer \Model \Url ;
17
+ use Magento \Framework \App \Action \Action ;
18
+ use Magento \Framework \App \Action \Context ;
19
+ use Magento \Framework \App \ObjectManager ;
20
+ use Magento \Framework \Registry ;
9
21
use Magento \Framework \App \RequestInterface ;
22
+ use Magento \Framework \Data \Form \FormKey \Validator ;
23
+ use Magento \Framework \Exception \LocalizedException ;
10
24
use Magento \Framework \Exception \NoSuchEntityException ;
25
+ use Magento \Framework \Session \Generic ;
26
+ use Magento \Review \Helper \Data ;
27
+ use Magento \Review \Model \RatingFactory ;
11
28
use Magento \Review \Model \Review ;
29
+ use Magento \Review \Model \Review \Config as ReviewsConfig ;
30
+ use Magento \Review \Model \ReviewFactory ;
31
+ use Magento \Store \Model \StoreManagerInterface ;
32
+ use Psr \Log \LoggerInterface ;
12
33
13
34
/**
14
35
* Review controller
15
36
*
16
37
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17
38
*/
18
- abstract class Product extends \ Magento \ Framework \ App \ Action \ Action
39
+ abstract class Product extends Action
19
40
{
20
41
/**
21
- * Core registry
42
+ * Core Registry class
22
43
*
23
- * @var \Magento\Framework\ Registry
44
+ * @var Registry
24
45
*/
25
46
protected $ coreRegistry = null ;
26
47
27
48
/**
28
49
* Customer session model
29
50
*
30
- * @var \Magento\Customer\Model\ Session
51
+ * @var Session
31
52
*/
32
53
protected $ customerSession ;
33
54
34
55
/**
35
56
* Generic session
36
57
*
37
- * @var \Magento\Framework\Session\ Generic
58
+ * @var Generic
38
59
*/
39
60
protected $ reviewSession ;
40
61
41
62
/**
42
63
* Catalog category model
43
64
*
44
- * @var \Magento\Catalog\Api\ CategoryRepositoryInterface
65
+ * @var CategoryRepositoryInterface
45
66
*/
46
67
protected $ categoryRepository ;
47
68
48
69
/**
49
- * Logger
70
+ * Logger for adding logs
50
71
*
51
- * @var \Psr\Log\ LoggerInterface
72
+ * @var LoggerInterface
52
73
*/
53
74
protected $ logger ;
54
75
55
76
/**
56
77
* Catalog product model
57
78
*
58
- * @var \Magento\Catalog\Api\ ProductRepositoryInterface
79
+ * @var ProductRepositoryInterface
59
80
*/
60
81
protected $ productRepository ;
61
82
62
83
/**
63
84
* Review model
64
85
*
65
- * @var \Magento\Review\Model\ ReviewFactory
86
+ * @var ReviewFactory
66
87
*/
67
88
protected $ reviewFactory ;
68
89
69
90
/**
70
91
* Rating model
71
92
*
72
- * @var \Magento\Review\Model\ RatingFactory
93
+ * @var RatingFactory
73
94
*/
74
95
protected $ ratingFactory ;
75
96
76
97
/**
77
98
* Catalog design model
78
99
*
79
- * @var \Magento\Catalog\Model\ Design
100
+ * @var Design
80
101
*/
81
102
protected $ catalogDesign ;
82
103
83
104
/**
84
105
* Core model store manager interface
85
106
*
86
- * @var \Magento\Store\Model\ StoreManagerInterface
107
+ * @var StoreManagerInterface
87
108
*/
88
109
protected $ storeManager ;
89
110
90
111
/**
91
112
* Core form key validator
92
113
*
93
- * @var \Magento\Framework\Data\Form\FormKey\ Validator
114
+ * @var Validator
94
115
*/
95
116
protected $ formKeyValidator ;
96
117
97
118
/**
98
- * @param \Magento\Framework\App\Action\Context $context
99
- * @param \Magento\Framework\Registry $coreRegistry
100
- * @param \Magento\Customer\Model\Session $customerSession
101
- * @param \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository
102
- * @param \Psr\Log\LoggerInterface $logger
103
- * @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
104
- * @param \Magento\Review\Model\ReviewFactory $reviewFactory
105
- * @param \Magento\Review\Model\RatingFactory $ratingFactory
106
- * @param \Magento\Catalog\Model\Design $catalogDesign
107
- * @param \Magento\Framework\Session\Generic $reviewSession
108
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
109
- * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
119
+ * Review config
120
+ *
121
+ * @var ReviewsConfig
122
+ */
123
+ protected $ reviewsConfig ;
124
+
125
+ /**
126
+ * @param Context $context
127
+ * @param Registry $coreRegistry
128
+ * @param Session $customerSession
129
+ * @param CategoryRepositoryInterface $categoryRepository
130
+ * @param LoggerInterface $logger
131
+ * @param ProductRepositoryInterface $productRepository
132
+ * @param ReviewFactory $reviewFactory
133
+ * @param RatingFactory $ratingFactory
134
+ * @param Design $catalogDesign
135
+ * @param Generic $reviewSession
136
+ * @param StoreManagerInterface $storeManager
137
+ * @param Validator $formKeyValidator
138
+ * @param ReviewsConfig $reviewsConfig
110
139
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
111
140
*/
112
141
public function __construct (
113
- \Magento \Framework \App \Action \Context $ context ,
114
- \Magento \Framework \Registry $ coreRegistry ,
115
- \Magento \Customer \Model \Session $ customerSession ,
116
- \Magento \Catalog \Api \CategoryRepositoryInterface $ categoryRepository ,
117
- \Psr \Log \LoggerInterface $ logger ,
118
- \Magento \Catalog \Api \ProductRepositoryInterface $ productRepository ,
119
- \Magento \Review \Model \ReviewFactory $ reviewFactory ,
120
- \Magento \Review \Model \RatingFactory $ ratingFactory ,
121
- \Magento \Catalog \Model \Design $ catalogDesign ,
122
- \Magento \Framework \Session \Generic $ reviewSession ,
123
- \Magento \Store \Model \StoreManagerInterface $ storeManager ,
124
- \Magento \Framework \Data \Form \FormKey \Validator $ formKeyValidator
142
+ Context $ context ,
143
+ Registry $ coreRegistry ,
144
+ Session $ customerSession ,
145
+ CategoryRepositoryInterface $ categoryRepository ,
146
+ LoggerInterface $ logger ,
147
+ ProductRepositoryInterface $ productRepository ,
148
+ ReviewFactory $ reviewFactory ,
149
+ RatingFactory $ ratingFactory ,
150
+ Design $ catalogDesign ,
151
+ Generic $ reviewSession ,
152
+ StoreManagerInterface $ storeManager ,
153
+ Validator $ formKeyValidator ,
154
+ ReviewsConfig $ reviewsConfig = null
125
155
) {
126
156
$ this ->storeManager = $ storeManager ;
127
157
$ this ->coreRegistry = $ coreRegistry ;
@@ -134,7 +164,7 @@ public function __construct(
134
164
$ this ->ratingFactory = $ ratingFactory ;
135
165
$ this ->catalogDesign = $ catalogDesign ;
136
166
$ this ->formKeyValidator = $ formKeyValidator ;
137
-
167
+ $ this -> reviewsConfig = $ reviewsConfig ?: ObjectManager:: getInstance ()-> get (ReviewsConfig::class);
138
168
parent ::__construct ($ context );
139
169
}
140
170
@@ -146,7 +176,7 @@ public function __construct(
146
176
*/
147
177
public function dispatch (RequestInterface $ request )
148
178
{
149
- $ allowGuest = $ this ->_objectManager ->get (\ Magento \ Review \ Helper \ Data::class)->getIsGuestAllowToWrite ();
179
+ $ allowGuest = $ this ->_objectManager ->get (Data::class)->getIsGuestAllowToWrite ();
150
180
if (!$ request ->isDispatched ()) {
151
181
return parent ::dispatch ($ request );
152
182
}
@@ -161,7 +191,7 @@ public function dispatch(RequestInterface $request)
161
191
$ this ->_redirect ->getRefererUrl ()
162
192
);
163
193
$ this ->getResponse ()->setRedirect (
164
- $ this ->_objectManager ->get (\ Magento \ Customer \ Model \ Url::class)->getLoginUrl ()
194
+ $ this ->_objectManager ->get (Url::class)->getLoginUrl ()
165
195
);
166
196
}
167
197
}
@@ -196,7 +226,7 @@ protected function initProduct()
196
226
'review_controller_product_init_after ' ,
197
227
['product ' => $ product , 'controller_action ' => $ this ]
198
228
);
199
- } catch (\ Magento \ Framework \ Exception \ LocalizedException $ e ) {
229
+ } catch (LocalizedException $ e ) {
200
230
$ this ->logger ->critical ($ e );
201
231
return false ;
202
232
}
@@ -205,8 +235,7 @@ protected function initProduct()
205
235
}
206
236
207
237
/**
208
- * Load product model with data by passed id.
209
- * Return false if product was not loaded or has incorrect status.
238
+ * Load product model with data by passed id. Return false if product was not loaded or has incorrect status.
210
239
*
211
240
* @param int $productId
212
241
* @return bool|CatalogProduct
0 commit comments