9
9
10
10
use Magento \Catalog \Model \Category as ModelCategory ;
11
11
use Magento \Catalog \Model \Product as ModelProduct ;
12
+ use Magento \Eav \Model \Config ;
13
+ use Magento \Framework \App \Helper \AbstractHelper ;
14
+ use Magento \Framework \App \Helper \Context ;
15
+ use Magento \Framework \Escaper ;
16
+ use Magento \Framework \Exception \LocalizedException ;
12
17
use Magento \Framework \Filter \Template ;
18
+ use function is_object ;
19
+ use function method_exists ;
20
+ use function preg_match ;
21
+ use function strtolower ;
13
22
14
- class Output extends \ Magento \ Framework \ App \ Helper \ AbstractHelper
23
+ class Output extends AbstractHelper
15
24
{
16
25
/**
17
26
* Array of existing handlers
@@ -37,12 +46,12 @@ class Output extends \Magento\Framework\App\Helper\AbstractHelper
37
46
/**
38
47
* Eav config
39
48
*
40
- * @var \Magento\Eav\Model\ Config
49
+ * @var Config
41
50
*/
42
51
protected $ _eavConfig ;
43
52
44
53
/**
45
- * @var \Magento\Framework\ Escaper
54
+ * @var Escaper
46
55
*/
47
56
protected $ _escaper ;
48
57
@@ -53,23 +62,26 @@ class Output extends \Magento\Framework\App\Helper\AbstractHelper
53
62
54
63
/**
55
64
* Output constructor.
56
- * @param \Magento\Framework\App\Helper\ Context $context
57
- * @param \Magento\Eav\Model\ Config $eavConfig
65
+ * @param Context $context
66
+ * @param Config $eavConfig
58
67
* @param Data $catalogData
59
- * @param \Magento\Framework\ Escaper $escaper
68
+ * @param Escaper $escaper
60
69
* @param array $directivePatterns
70
+ * @param array $handlers
61
71
*/
62
72
public function __construct (
63
- \ Magento \ Framework \ App \ Helper \ Context $ context ,
64
- \ Magento \ Eav \ Model \ Config $ eavConfig ,
73
+ Context $ context ,
74
+ Config $ eavConfig ,
65
75
Data $ catalogData ,
66
- \Magento \Framework \Escaper $ escaper ,
67
- $ directivePatterns = []
76
+ Escaper $ escaper ,
77
+ $ directivePatterns = [],
78
+ array $ handlers = []
68
79
) {
69
80
$ this ->_eavConfig = $ eavConfig ;
70
81
$ this ->_catalogData = $ catalogData ;
71
82
$ this ->_escaper = $ escaper ;
72
83
$ this ->directivePatterns = $ directivePatterns ;
84
+ $ this ->_handlers = $ handlers ;
73
85
parent ::__construct ($ context );
74
86
}
75
87
@@ -115,8 +127,7 @@ public function addHandler($method, $handler)
115
127
*/
116
128
public function getHandlers ($ method )
117
129
{
118
- $ method = strtolower ($ method );
119
- return $ this ->_handlers [$ method ] ?? [];
130
+ return $ this ->_handlers [strtolower ($ method )] ?? [];
120
131
}
121
132
122
133
/**
@@ -145,21 +156,21 @@ public function process($method, $result, $params)
145
156
* @param string $attributeName
146
157
* @return string
147
158
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
148
- * @throws \Magento\Framework\Exception\ LocalizedException
159
+ * @throws LocalizedException
149
160
*/
150
161
public function productAttribute ($ product , $ attributeHtml , $ attributeName )
151
162
{
152
163
$ attribute = $ this ->_eavConfig ->getAttribute (ModelProduct::ENTITY , $ attributeName );
153
164
if ($ attribute &&
154
165
$ attribute ->getId () &&
155
- $ attribute ->getFrontendInput () != 'media_image ' &&
166
+ $ attribute ->getFrontendInput () !== 'media_image ' &&
156
167
(!$ attribute ->getIsHtmlAllowedOnFront () &&
157
168
!$ attribute ->getIsWysiwygEnabled ())
158
169
) {
159
- if ($ attribute ->getFrontendInput () != 'price ' ) {
170
+ if ($ attribute ->getFrontendInput () !== 'price ' ) {
160
171
$ attributeHtml = $ this ->_escaper ->escapeHtml ($ attributeHtml );
161
172
}
162
- if ($ attribute ->getFrontendInput () == 'textarea ' ) {
173
+ if ($ attribute ->getFrontendInput () === 'textarea ' ) {
163
174
$ attributeHtml = nl2br ($ attributeHtml );
164
175
}
165
176
}
@@ -187,14 +198,14 @@ public function productAttribute($product, $attributeHtml, $attributeName)
187
198
* @param string $attributeHtml
188
199
* @param string $attributeName
189
200
* @return string
190
- * @throws \Magento\Framework\Exception\ LocalizedException
201
+ * @throws LocalizedException
191
202
*/
192
203
public function categoryAttribute ($ category , $ attributeHtml , $ attributeName )
193
204
{
194
205
$ attribute = $ this ->_eavConfig ->getAttribute (ModelCategory::ENTITY , $ attributeName );
195
206
196
207
if ($ attribute &&
197
- $ attribute ->getFrontendInput () != 'image ' &&
208
+ $ attribute ->getFrontendInput () !== 'image ' &&
198
209
(!$ attribute ->getIsHtmlAllowedOnFront () &&
199
210
!$ attribute ->getIsWysiwygEnabled ())
200
211
) {
0 commit comments